Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
27 changes: 27 additions & 0 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,52 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];

function getLength(arr, cb) {
// getLength passes the length of the array into the callback.
cb = arr.length;
return cb;
}

console.log(getLength(items));

function last(arr, cb) {
// last passes the last item of the array into the callback.
cb = arr[arr.length - 1]
return cb;
}

console.log(last(items));


function sumNums(x, y, cb) {
// sumNums adds two numbers (x, y) and passes the result to the callback.
cb = x + y;
return cb;
}

console.log(sumNums(2, 3))

function multiplyNums(x, y, cb) {
// multiplyNums multiplies two numbers and passes the result to the callback.
cb = x * y;
return cb;
}

console.log(multiplyNums(2, 3))

function contains(item, list, cb) {
// contains checks if an item is present inside of the given array/list.
// Pass true to the callback if it is, otherwise pass false.
for (let i = 0; i < list.length; i++) {
if (list[i] === item) {
cb = true;
} else {
cb = false;
}
}
return cb;
}

console.log(contains('Daisy', items))

/* STRETCH PROBLEM */

function removeDuplicates(array, cb) {
Expand Down