1- // Complete the following functions.
2- // These functions only need to work with arrays.
3- // Do NOT use the built in array methods to solve these. forEach, map, reduce, filter, includes, etc.
4- // You CAN use concat, push, pop, etc. but do not use the exact method that you are replicating
5- // You can use the functions that you have already written to help solve the other problems
1+ /*
2+ Complete the following functions.
3+ These functions only need to work with arrays.
4+ A few of these functions mimic the behavior of the `Built` in JavaScript Array Methods.
5+ The idea here is to recreate the functions from scratch BUT if you'd like,
6+ feel free to Re-use any of your functions you build within your other functions.
7+ You CAN use concat, push, pop, etc. but do not use the exact method that you are replicating
8+ You can use the functions that you have already written to help solve the other problems
9+ */
610
711const each = ( elements , cb ) => {
12+ // Do NOT use forEach to complete this function.
813 // Iterates over a list of elements, yielding each in turn to the `cb` function.
914 // This only needs to work with arrays.
1015 // You should also pass the index into `cb` as the second argument
1116 // based off http://underscorejs.org/#each
1217} ;
1318
1419const map = ( elements , cb ) => {
20+ // Do NOT use .map, to complete this function.
1521 // Produces a new array of values by mapping each value in list through a transformation function (iteratee).
1622 // Return the new array.
1723} ;
1824
1925const reduce = ( elements , cb , startingValue ) => {
26+ // Do NOT use .reduce, to complete this function.
2027 // Combine all elements into a single value going from left to right.
2128 // Elements will be passed one by one into `cb` along with the `startingValue`.
2229 // `startingValue` should be the first argument passed to `cb` and the array element should be the second argument.
2330 // `startingValue` is the starting value. If `startingValue` is undefined then make `elements[0]` the initial value.
2431} ;
2532
2633const find = ( elements , cb ) => {
34+ // Do NOT use .includes, to complete this function.
2735 // Look through each value in `elements` and pass each element to `cb`.
2836 // If `cb` returns `true` then return that element.
2937 // Return `undefined` if no elements pass the truth test.
3038} ;
3139
3240const filter = ( elements , cb ) => {
41+ // Do NOT use .filter, to complete this function.
3342 // Similar to `find` but you will return an array of all elements that passed the truth test
3443 // Return an empty array if no elements pass the truth test
3544} ;
@@ -49,5 +58,5 @@ module.exports = {
4958 reduce,
5059 find,
5160 filter,
52- flatten,
61+ flatten
5362} ;
0 commit comments