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