Skip to content

Commit

Permalink
finished callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Abott1222 committed Nov 27, 2018
1 parent ae46db5 commit 306e976
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,37 @@ last(items, function(last) {

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

sumNums(100,1, function(sum) {
console.log(sum);
})

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


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(items[i] === item) {
return cb(true);
}
}
return cb(false);
}

contains(items[2], items, function(bool) {
console.log(bool);
})

/* STRETCH PROBLEM */

function removeDuplicates(array, cb) {
Expand Down

0 comments on commit 306e976

Please sign in to comment.