Skip to content

Commit 79a32cd

Browse files
author
Emily McClanahan
committed
task two completed
1 parent 1146fc5 commit 79a32cd

1 file changed

Lines changed: 33 additions & 11 deletions

File tree

‎assignments/callbacks.js‎

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,54 @@
11
const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
22

33
function firstItem(arr, cb) {
4-
// firstItem passes the first item of the given array to the callback function.
4+
return cb(arr[0]);
55
}
6-
6+
firstItem(items, function(first) {
7+
console.log(first);
8+
});
9+
//------------------------------------------//
710
function getLength(arr, cb) {
8-
// getLength passes the length of the array into the callback.
11+
return cb(arr[0]);
912
}
10-
13+
getLength(items, function() {
14+
console.log(items.length);
15+
});
16+
//------------------------------------------//
1117
function last(arr, cb) {
12-
// last passes the last item of the array into the callback.
18+
return cb(arr[3]);
1319
}
14-
20+
last (items, function(final) {
21+
console.log(final);
22+
});
23+
//------------------------------------------//
1524
function sumNums(x, y, cb) {
16-
// sumNums adds two numbers (x, y) and passes the result to the callback.
25+
return cb(x,y);
26+
}
27+
28+
function add (x,y){
29+
console.log (x + y)
1730
}
31+
sumNums(2,4, add);
1832

1933
function multiplyNums(x, y, cb) {
20-
// multiplyNums multiplies two numbers and passes the result to the callback.
34+
return cb(x,y);
2135
}
2236

23-
function 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.
37+
function multiply (x,y){
38+
console.log (x * y);
2639
}
40+
sumNums(2,4, multiply);
2741

42+
//------------------------------------------//
2843
/* STRETCH PROBLEM */
2944

45+
// contains checks if an item is present inside of the given array/list.
46+
// Pass true to the callback if it is, otherwise pass false.
47+
function contains(item, list, cb) {
48+
49+
}
50+
51+
3052
function removeDuplicates(array, cb) {
3153
// removeDuplicates removes all duplicate values from the given array.
3254
// Pass the duplicate free array to the callback function.

0 commit comments

Comments
 (0)