|
1 | | -// Do not change any of the function names |
2 | | - |
3 | | -const multiplyArguments = () => { |
4 | | - // use the spread operator (...args) to multiply all of the arguments together and return the product |
5 | | - // if no arguments are passed in return 0 |
6 | | - // if one argument is passed in just return it |
7 | | -}; |
8 | | - |
9 | | -const invokeCallback = (cb) => { |
10 | | - // invoke cb |
11 | | -}; |
12 | | - |
13 | | -const sumArray = (numbers, cb) => { |
14 | | - // sum up all of the integers in the numbers array |
15 | | - // pass the result to cb |
16 | | - // no return is necessary |
| 1 | +const getFirstItem = (collection, cb) => { |
| 2 | + // invoke the callback function and pass the first item from the collection in as an argument |
17 | 3 | }; |
18 | 4 |
|
19 | | -const forEach = (arr, cb) => { |
20 | | - // iterate over arr and pass its values to cb one by one |
21 | | - // hint: you will be invoking cb multiple times (once for each value in the array) |
| 5 | +const getLength = (collection, cb) => { |
| 6 | + // Write a function called getLength that passes the length of the array into the callback |
22 | 7 | }; |
23 | 8 |
|
24 | | -const map = (arr, cb) => { |
25 | | - // create a new array |
26 | | - // iterate over each value in arr, pass it to cb, then place the value returned from cb into the new arr |
27 | | - // the new array should be the same length as the array argument |
| 9 | +const getLastItem = (collection, cb) => { |
| 10 | + // Write a function called getLastItem which passes the getLastItem item of the array into the callback |
28 | 11 | }; |
29 | 12 |
|
30 | | -const getUserConstructor = () => { |
31 | | - // create a constructor called User |
32 | | - // it should accept an options object with username, name, email, and password properties |
33 | | - // in the constructor set the username, name, email, and password properties |
34 | | - // the constructor should have a method 'sayHi' on its prototype that returns the string 'Hello, my name is {{name}}' |
35 | | - // {{name}} should be the name set on each instance |
36 | | - // return the constructor |
| 13 | +const sumNums = (x, y, cb) => { |
| 14 | + // Write a function called sumNums that adds two numbers and passes the result to the callback |
37 | 15 | }; |
38 | 16 |
|
39 | | -const addPrototypeMethod = (Constructor) => { |
40 | | - // add a method to the constructor's prototype |
41 | | - // the method should be called 'sayHi' and should return the string 'Hello World!' |
| 17 | +const multiplyNums = (x, y, cb) => { |
| 18 | + // Write a function called multiplyNums that adds two numbers and passes the result to the callback |
42 | 19 | }; |
43 | 20 |
|
44 | | -const addReverseString = () => { |
45 | | - // add a method to the string constructor's prototype that returns a reversed copy of the string |
46 | | - // name this method reverse |
47 | | - // hint: |
48 | | - // you will need to use 'this' inside of reverse |
| 21 | +const contains = (collection, item, cb) => { |
| 22 | + // Write a function called contains that checks if an item is present inside of the given array. |
| 23 | + // Pass true to the callback if it is, otherwise pass false |
49 | 24 | }; |
50 | 25 |
|
51 | | -const nFactorial = (n) => { |
52 | | - // return the factorial for n |
53 | | - // solve this recursively |
54 | | - // example: |
55 | | - // the factorial of 3 is 6 (3 * 2 * 1) |
| 26 | +const removeDuplicates = (collection, cb) => { |
| 27 | + // Write a function called removeDuplicates that removes all duplicate values from the given array. |
| 28 | + // Pass the array to the callback function. Do not mutate the original array. |
56 | 29 | }; |
57 | 30 |
|
58 | | -const cacheFunction = (cb) => { |
59 | | - // Extra Credit |
60 | | - // use closure to create a cache for the cb function |
61 | | - // the function that you return should accept a single argument and invoke cb with that argument |
62 | | - // when the function you return is invoked with an argument it should save that argument and its result |
63 | | - // when the function you return is called again with an argument that it has seen before it should not call cb |
64 | | - // but should instead directly returned the previous result |
65 | | - // example: |
66 | | - // cb -> function(x) { return x * x; } |
67 | | - // if the function you return is invoked with 5 it would pass 5 to cb(5) and return 25 |
68 | | - // if the function you return is invoked again with 5 it will look on an object in the closure scope |
69 | | - // and return 25 directly and will not invoke cb again |
70 | | -}; |
71 | | - |
72 | | - |
73 | | -// Do not modify code below this line. |
74 | | -// -------------------------------- |
75 | | - |
76 | 31 | module.exports = { |
77 | | - multiplyArguments, |
78 | | - invokeCallback, |
79 | | - sumArray, |
80 | | - forEach, |
81 | | - map, |
82 | | - getUserConstructor, |
83 | | - addPrototypeMethod, |
84 | | - addReverseString, |
85 | | - nFactorial, |
86 | | - cacheFunction |
| 32 | + getFirstItem, |
| 33 | + getLength, |
| 34 | + getLastItem, |
| 35 | + sumNums, |
| 36 | + multiplyNums, |
| 37 | + contains, |
| 38 | + removeDuplicates |
87 | 39 | }; |
0 commit comments