-
Notifications
You must be signed in to change notification settings - Fork 269
tests passed #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests passed #1
Conversation
| // Return the new array. | ||
| }; | ||
|
|
||
| const reduce = (elements, cb, startingValue) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also do this for a starting value: (elements, cb, startingValue = elements.shift()) for the default value. This takes advantage of the ES6 default parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless of course you are avoiding modifying the input array
src/arrays.js
Outdated
| // Elements will be passed one by one into `cb`. | ||
| // `startingValue` is the starting value. If `startingValue` is undefined then make `elements[0]` the initial value. | ||
| if (startingValue === undefined) { | ||
| startingValue = (typeof elements[0]) === 'string' ? '' : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just make startingValue the first item from the array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A reduce is supposed to have the first item in the array as its initial memo
| const map = (elements, cb) => { | ||
| // Produces a new array of values by mapping each value in list through a transformation function (iteratee). | ||
| // Return the new array. | ||
| return reduce(elements, (acc, v) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really creative
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
src/arrays.js
Outdated
| /* Extra Credit */ | ||
|
|
||
| function isArray(elements) { | ||
| return (Object.prototype.toString.call(elements) === '[object Array]'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The preferred way of checking whether a variable is an array or not is this: Array.isArray(myVariable);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job creating another function though
src/callbacks.js
Outdated
| // code here | ||
|
|
||
| const foods = ['pineapple', 'mango', 'ribeye', 'curry', 'tacos', 'ribeye', 'mango']; | ||
| function firstItem(foods,f) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer it if you put a space between the parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accustomed to getting a 'comma-spacing' error by the eslint configs I have been working with
src/callbacks.js
Outdated
|
|
||
| const foods = ['pineapple', 'mango', 'ribeye', 'curry', 'tacos', 'ribeye', 'mango']; | ||
| function firstItem(foods,f) { | ||
| return f(foods[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should have a semicolon
src/callbacks.js
Outdated
| // code here | ||
|
|
||
| function getLength(foods,f) { | ||
| return f(foods.length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure that you stay consistent. Inconsistent code is a mark of an inexperienced developer. It shows experience and discipline to keep your code consistent.
| return Object.keys(obj); | ||
| }; | ||
|
|
||
| function isFunction(func) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the sake of consistency this should be written the same way the other functions are written.
tests/arrays.test.js
Outdated
| const result = arrayMethods.reduce(arr, callBackMockFn); | ||
| expect(result).toBe(25); | ||
| expect(callBackMockFn.mock.calls.length).toBe(4); | ||
| expect(callBackMockFn.mock.calls.length).toBe(5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should not be modified. The memo in the reduce should be the first item from the array and so the callback would only be invoked 4 times.
No description provided.