Skip to content

Commit 91ff21a

Browse files
committed
Adding callbacks
1 parent a1dd794 commit 91ff21a

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ With some basic JavaScript principles we can now expand our skills out even furt
99
* 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`.
1010
* Once you finish the exercises in each file, commit your code, and push it to your fork.
1111

12+
### Callbacks
13+
14+
* 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.
15+
* Write out each function using the `ES5` `function` keyword syntax.
16+
* Remember that a callback function is simply a function that is being passed around to other functions.
17+
* **Stretch Problem** After you're done with all of the functions, go ahead and re-factor all of them to use `ES6` `Arrow Functions`
18+
1219
### Function Conversion
1320
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.
1421

assignments/callbacks.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2+
3+
function firstItem(arr, cb) {
4+
// firstItem passes the first item of the given array to the callback function.
5+
}
6+
7+
function getLength(arr, cb) {
8+
// getLength passes the length of the array into the callback.
9+
}
10+
11+
function last(arr, cb) {
12+
// last passes the last item of the array into the callback.
13+
}
14+
15+
function sumNums(x, y, cb) {
16+
// sumNums adds two numbers (x, y) and passes the result to the callback.
17+
}
18+
19+
function multiplyNums(x, y, cb) {
20+
// multiplyNums multiplies two numbers and passes the result to the callback.
21+
}
22+
23+
function contains(item, list, cb) {
24+
// contains checks if an item is present inside of the given array/list.
25+
// Pass true to the callback if it is, otherwise pass false.
26+
}
27+
28+
/* STRETCH PROBLEM */
29+
30+
function removeDuplicates(array, cb) {
31+
// removeDuplicates removes all duplicate values from the given array.
32+
// Pass the duplicate free array to the callback function.
33+
// Do not mutate the original array.
34+
}

0 commit comments

Comments
 (0)