Skip to content

Commit 2f627d5

Browse files
committed
refactured functions to be arrow functions
1 parent b7ea744 commit 2f627d5

3 files changed

Lines changed: 25 additions & 32 deletions

File tree

assignments/array-methods.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
6161
let fullName = [];
6262
console.log(fullName);
6363

64-
runners.forEach(function(getNames){
65-
let names = getNames.first_name + " " + getNames.last_name;
64+
runners.forEach((getNames) => {
65+
// let names = getNames.first_name + " " + getNames.last_name;
66+
let names = `${getNames.first_name} ${getNames.last_name}`
6667
fullName.push(names)
6768
});
6869

@@ -121,7 +122,7 @@ console.log(totalPrices2)
121122
// emailInfo.push(racer.email)
122123
// }
123124

124-
runners.forEach(function(racer){
125+
runners.forEach((racer) => {
125126
emailInfo.push(racer.email)
126127
})
127128

assignments/callbacks.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,41 +26,41 @@ const items2 = ['Pencil', 'Notebook', 'yo-yo', 'Gum', 'Gum', 'yarn', 'yo-yo' ];
2626
2727
*/
2828
console.log(`********* callback.js challenges *********`)
29-
function getLength(arr, cb) {
29+
const getLength = (arr, cb) => {
3030
// getLength passes the length of the array into the callback.
3131
return cb(arr.length)
3232
}
3333

34-
getLength(items, function(theLength){
34+
getLength(items, (theLength) => {
3535
console.log("getLength function: ", theLength)
3636
})
3737

38-
function last(arr, cb) {
38+
const last = (arr, cb) => {
3939
// last passes the last item of the array into the callback.
4040
return cb(arr.length - 1)
4141
}
4242

43-
last(items, function(lastItem){
43+
last(items, (lastItem) =>{
4444
console.log(`lastItem function: ${lastItem}`);
4545
console.dir(lastItem);
4646
})
4747

4848

49-
function sumNums(x, y, cb) {
49+
const sumNums = (x, y, cb) => {
5050
// sumNums adds two numbers (x, y) and passes the result to the callback.
5151
return cb(x + y);
5252
}
5353

54-
sumNums(3, 4, function(sum){
54+
sumNums(3, 4, (sum) => {
5555
console.log('the sum is: ', sum)
5656
})
5757

58-
function multiplyNums(x, y, cb) {
58+
const multiplyNums = (x, y, cb) => {
5959
return cb(x * y)
6060
// multiplyNums multiplies two numbers and passes the result to the callback.
6161
}
6262

63-
multiplyNums(3, 4, function(mult){
63+
multiplyNums(3, 4,(mult) => {
6464
console.log("the multiplied value is: ", mult)
6565
})
6666

@@ -72,7 +72,7 @@ multiplyNums(3, 4, function(mult){
7272

7373
// multiplyNums(2, 4, multiplying)
7474

75-
function contains(item, list, cb) {
75+
const contains = (item, list, cb) => {
7676
// contains checks if an item is present inside of the given array/list.
7777
// Pass true to the callback if it is, otherwise pass false.
7878
return cb(item, list)
@@ -81,7 +81,7 @@ function contains(item, list, cb) {
8181
}
8282

8383
// researched "includes" method from MDN
84-
function inventory(item, list){
84+
const inventory = (item, list) =>{
8585
return list.includes(item)
8686
}
8787

@@ -100,14 +100,14 @@ function inventory(item, list){
100100

101101
/* STRETCH PROBLEM */
102102

103-
function removeDuplicates(array, cb) {
103+
const removeDuplicates = (array, cb) => {
104104
// removeDuplicates removes all duplicate values from the given array.
105105
// Pass the duplicate free array to the callback function.
106106
// Do not mutate the original array.
107107
return cb(array)
108108
}
109109

110-
function removeThem(array){
110+
const removeThem =(array) =>{
111111
return array.filter(function(item, index){
112112
return array.indexOf(item) >= index;
113113
});
@@ -118,4 +118,4 @@ function removeThem(array){
118118

119119
// created duplicate items array to check if it worked
120120
removeDuplicates(items2, removeThem)
121-
console.log("Removed duplicates from array of items2:", removeDuplicates(items2, removeThem))
121+
console.log("Removed duplicates from array of items2:", removeDuplicates(items2, removeThem))

assignments/closure.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,8 @@ const whoIsThatPokemon = () => {
1414
espeon()
1515
}
1616

17-
// function whoIsThatPokemon2 () {
18-
// let pokemon = "Pikachu"
19-
// console.log(pokemon)
20-
21-
// espeon()
22-
// function espeon () {
23-
// pokemon = "Espeon";
24-
// console.log(pokemon);
25-
26-
// }
27-
// }
2817

2918
whoIsThatPokemon()
30-
// whoIsThatPokemon2()
31-
32-
// console.log(whoIsThatPokemon);
33-
// console.log(whoIsThatPokemon2());
3419

3520

3621
// ==== Challenge 2: Create a counter function ====
@@ -77,5 +62,12 @@ const counterFactory = () => {
7762
// `decrement` should decrement the counter variable and return it.
7863
};
7964
const counter2 = counterFactory();
80-
console.log(counter2.increment(3))
65+
66+
counter2.increment()
8167
counter2.increment()
68+
69+
console.log(counter2.increment())
70+
71+
counter2.decrement()
72+
73+
console.log(counter2.decrement())

0 commit comments

Comments
 (0)