|
1 | 1 | /* eslint-disable */ |
2 | 2 |
|
3 | | -/* For a portion of the assignment your job is to write functions |
4 | | - * so that each function invocation below works. You're working backwards. |
5 | | - * |
6 | | - * There are no tests for this file. |
7 | | - * |
8 | | - * Example: |
9 | | - * |
10 | | - * greeting('Hey guys', (message) => { |
11 | | - * console.log(message); |
12 | | - * }); |
13 | | - * |
14 | | - * You would then define the greeting function to make the invocation work. |
15 | | - * |
16 | | - * |
17 | | - * const greeting = (str, cb) => { |
18 | | - * cb(str); |
19 | | - * }; |
20 | | - * |
21 | | - */ |
| 3 | +const firstItem = (arr, cb) => { |
| 4 | + // firstItem passes the first item of the given array to the callback function. |
| 5 | +}; |
22 | 6 |
|
23 | | -// Write a function called firstItem that passes the first item of the given array to the callback function |
24 | | -// code here |
| 7 | +const getLength = (arr, cb) => { |
| 8 | + // getLength passes the length of the array into the callback. |
| 9 | +}; |
25 | 10 |
|
26 | | -const foods = ['pineapple', 'mango', 'ribeye', 'curry', 'tacos', 'ribeye', 'mango']; |
| 11 | +const last = (arr, cb) => { |
| 12 | + // last passes the last item of the array into the callback. |
| 13 | +}; |
27 | 14 |
|
28 | | -firstItem(foods, (firstItem) => { |
29 | | - console.log(`The first item is ${firstItem}.`); |
30 | | -}); |
| 15 | +const sumNums = (x, y, cb) => { |
| 16 | + // sumNums adds two numbers (x, y) and passes the result to the callback. |
| 17 | +}; |
31 | 18 |
|
32 | | -// Write a function called getLength that passes the length of the array into the callback |
33 | | -// code here |
| 19 | +const multiplyNums = (x, y, cb) => { |
| 20 | + // multiplyNums multiplies two numbers and passes the result to the callback. |
| 21 | +}; |
34 | 22 |
|
35 | | -getLength(foods, (length) => { |
36 | | - console.log(`The length of the array is ${length}.`); |
37 | | -}); |
| 23 | +const contains = (item, list, cb) => { |
| 24 | + // contains checks if an item is present inside of the given array/list. |
| 25 | + // Pass true to the callback if it is, otherwise pass false. |
| 26 | +}; |
38 | 27 |
|
39 | | -// Write a function called last which passes the last item of the array into the callback |
40 | | -// code here |
41 | | - |
42 | | -last(foods, (lastItem) => { |
43 | | - console.log(`The last item in the array is ${lastItem}.`); |
44 | | -}); |
45 | | - |
46 | | -// Write a function called sumNums that adds two numbers and passes the result to the callback |
47 | | -// code here |
48 | | - |
49 | | -sumNums(5, 10, (sum) => { |
50 | | - console.log(`The sum is ${sum}.`); |
51 | | -}); |
52 | | - |
53 | | -// Write a function called multiplyNums that multiplies two numbers and passes the result to the callback |
54 | | -// code here |
55 | | - |
56 | | -multiplyNums(5, 10, (product) => { |
57 | | - console.log(`The product is ${product}.`); |
58 | | -}); |
59 | | - |
60 | | -// Write a function called contains that checks if an item is present inside of the given array. |
61 | | -// Pass true to the callback if it is, otherwise pass false |
62 | | -// code here |
63 | | - |
64 | | -contains(foods, 'ribeye', (result) => { |
65 | | - console.log(result ? 'ribeye is in the array' : 'ribeye is not in the array'); |
66 | | -}); |
67 | | - |
68 | | -// Write a function called removeDuplicates that removes all duplicate values from the given array. |
69 | | -// Pass the array to the callback function. Do not mutate the original array. |
70 | | -// code here |
71 | | - |
72 | | -removeDuplicates(foods, (uniqueFoods) => { |
73 | | - console.log(`foods with duplicates removed: ${uniqueFoods}`); |
74 | | -}); |
75 | | - |
76 | | -// Write a function called forEach that iterates over the provided array and passes the value and index into the callback. |
77 | | -// code here |
78 | | - |
79 | | -forEach(foods, (value, index) => { |
80 | | - console.log(`${value} is at index ${index}.`); |
81 | | -}); |
| 28 | +const removeDuplicates = (array, cb) => { |
| 29 | + // removeDuplicates removes all duplicate values from the given array. |
| 30 | + // Pass the duplicate free array to the callback function. |
| 31 | + // Do not mutate the original array. |
| 32 | +}; |
82 | 33 |
|
83 | 34 | /* eslint-enable */ |
| 35 | +module.exports = { |
| 36 | + firstItem, |
| 37 | + getLength, |
| 38 | + last, |
| 39 | + sumNums, |
| 40 | + multiplyNums, |
| 41 | + contains, |
| 42 | + removeDuplicates, |
| 43 | +}; |
0 commit comments