Comments (3)
Here's a dump of some the code I used, reverse chronological:
'use strict';
let count = 0;
const counterFactory = function () {
return function counter () {
return count += 1;
};
};
const isCentimeters = function (value) {
if (value > 100) {
return true;
} else {
return false;
}
};
const fromCmToIn = function (value) {
return value * 0.39;
};
// const fromInToCm = function (value) {
// return value * 2.54;
// };
const transform = function (values, predicate, mutator) {
// if the predicate is true, mutate the value, otherwise don't mutate it
let result = [];
for (let i = 0; i < values.length; i++) {
let value = values[i];
if (predicate(value)) {
result.push(mutator(value));
} else {
result.push(value);
}
}
return result;
};
const addProperty = function addProperty(obj, prop, val) {
// this function takes an object and adds a property
// to it
// let prop = arguments[1];
// let val = arguments[2];
// let result = arguments[0];
obj[prop] = val;
return obj;
};
const arrayTimes2 = function arrayTimes2() {
let result = [];
for (let i = 0; i < arguments[0].length; i++) {
result[i] = arguments[0][i] * 2;
}
return result;
};
//const max = function (arrayOfNumbers) {
const max = function () {
// takes an arbitrary number of arguments (each arg
// should be a number), finds the largest one, and
// returns that member
//
// does it take negatives?
// we need a starting point (maybe the first argument)
let result = arguments[0][0];
for (let i = 1; i < arguments[0].length; i++) {
if (result < arguments[0][i]) {
result = arguments[0][i];
}
}
return result;
};
const product = function () {
// multiply two numbers and return the result
// return a * b;
// return arguments[0] * arguments[1];
// return arguments[0] * arguments[1] * arguments[2];
let result = 1;
for (let i = 0; i < arguments.length; i++) {
//result = result * args...
result = result * arguments[i];
}
return result;
};
from js-functions-ins-and-outs.
This should be included in the ins.js
and outs.js
. I missed these when prepping. Apologies.
from js-functions-ins-and-outs.
Leaving open for now. The solution branch needs updating, as noted in #35.
from js-functions-ins-and-outs.
Related Issues (20)
- README code is double wrong HOT 5
- Add scope to learning objectives, and add content about scope HOT 5
- PVD Thoughts (Did not deliver) HOT 3
- Did we lose a solution or demo branch? HOT 4
- Avoid mutating arguments to functions HOT 2
- Maintain code in one place
- Solution Branch needs to mirror Master HOT 1
- Remove profanity HOT 3
- more clear definition of the different types of functions? HOT 3
- Debugging Variable Scope Code Along should be in bin to run with node HOT 1
- Function Add should + not -
- Replace `unlimited` with `arbitrary`
- JS file names should be hyphenated not underscored
- Annotate use of `num` as variable and as parameter HOT 1
- `honesty_lab` file should match README code
- Remove code from README HOT 1
- Honest Lab is too negative. We need a better example.
- Typo memofactory must be memoFactory
- Code along example is broken HOT 1
- The memo example is wrong, or I don't understand the intent. Help? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-functions-ins-and-outs.