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
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ With some basic JavaScript principles in hand, we can now expand our skills out

**Follow these steps to set up and work on your project:**

* [ ] Create a forked copy of this project.
* [ ] Add your project manager as collaborator on Github.
* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!).
* [ ] Create a new branch: git checkout -b `<firstName-lastName>`.
* [ ] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [ ] Push commits: git push origin `<firstName-lastName>`.
* [ x] Create a forked copy of this project.
* [ x] Add your project manager as collaborator on Github.
* [ x] Clone your OWN version of the repository (Not Lambda's by mistake!).
* [ x] Create a new branch: git checkout -b `<firstName-lastName>`.
* [ x] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [ x] Push commits: git push origin `<firstName-lastName>`.

**Follow these steps for completing your project.**

* [ ] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo). **Please don't merge your own pull request**
* [ ] Add your project manager as a reviewer on the pull-request
* [ ] Your project manager will count the project as complete by merging the branch back into master.
* [ x] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo). **Please don't merge your own pull request**
* [ x] Add your project manager as a reviewer on the pull-request
* [ x] Your project manager will count the project as complete by merging the branch back into master.

## Task 2: Higher Order Functions and Callbacks

Expand Down
36 changes: 32 additions & 4 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];

/*


//Given this problem:

Expand All @@ -22,30 +22,58 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
console.log(first)
});

*/



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

getLength(items, function(x) {
console.log(x)
})


function last(arr, cb) {
// last passes the last item of the array into the callback.
return cb(arr[3])
}

last(items, function(last){console.log(last)} )

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

function sum(x,y) {
return x + y
}

console.log(sumNums(5, 6, sum))

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

function product(x,y) {
return x * y
}

console.log(multiplyNums(5, 5, 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.
return cb(item, list)
}

function checkFor(item, list){
return list.includes(item)
}

console.log(contains('yo-yo', items, checkFor))

/* STRETCH PROBLEM */

function removeDuplicates(array, cb) {
Expand Down