Skip to content

Commit

Permalink
Adding callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
BigKnell committed May 22, 2018
1 parent a1dd794 commit 91ff21a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ With some basic JavaScript principles we can now expand our skills out even furt
* To test your `console` statements you can run `node /assignments/<fileName>` and see what prints in your terminal. You can also use an online tool like `JSBin`, `REPL.it`, `JSFiddle`, or even your `Chrome developer console`.
* Once you finish the exercises in each file, commit your code, and push it to your fork.

### Callbacks

* In the [callbacks.js](assignments/callbacks.js) file you'll be receiving a lot of practice on how to use callbacks to pass around data.
* Write out each function using the `ES5` `function` keyword syntax.
* Remember that a callback function is simply a function that is being passed around to other functions.
* **Stretch Problem** After you're done with all of the functions, go ahead and re-factor all of them to use `ES6` `Arrow Functions`

### Function Conversion
You will see more and more arrow functions as you progress deeper into JavaScript. Use the [function-conversion.js](assignments/function-conversion.js) file as a helper challenge to showcase some of the differences between ES5 and ES6 syntax.

Expand Down
34 changes: 34 additions & 0 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];

function firstItem(arr, cb) {
// firstItem passes the first item of the given array to the callback function.
}

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

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

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

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

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.
}

/* STRETCH PROBLEM */

function removeDuplicates(array, cb) {
// removeDuplicates removes all duplicate values from the given array.
// Pass the duplicate free array to the callback function.
// Do not mutate the original array.
}

0 comments on commit 91ff21a

Please sign in to comment.