Skip to content

Commit f9ca3fd

Browse files
committed
Callbacks
1 parent f157eec commit f9ca3fd

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

assignments/callbacks.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,34 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
22

33
function firstItem(arr, cb) {
44
// firstItem passes the first item of the given array to the callback function.
5+
cb(arr[0])
56
}
67

78
function getLength(arr, cb) {
89
// getLength passes the length of the array into the callback.
10+
cb(arr.length)
911
}
1012

1113
function last(arr, cb) {
1214
// last passes the last item of the array into the callback.
15+
cb(arr[arr.length - 1])
1316
}
1417

1518
function sumNums(x, y, cb) {
1619
// sumNums adds two numbers (x, y) and passes the result to the callback.
20+
cb(x + y)
1721
}
1822

1923
function multiplyNums(x, y, cb) {
2024
// multiplyNums multiplies two numbers and passes the result to the callback.
25+
cb(x * y)
2126
}
2227

2328
function contains(item, list, cb) {
2429
// contains checks if an item is present inside of the given array/list.
2530
// Pass true to the callback if it is, otherwise pass false.
31+
cb(list.includes(item))
32+
2633
}
2734

2835
/* STRETCH PROBLEM */

0 commit comments

Comments
 (0)