Skip to content

Commit 047471e

Browse files
completed project function conversion included
1 parent b18ac72 commit 047471e

2 files changed

Lines changed: 29 additions & 29 deletions

File tree

‎assignments/callbacks.js‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,36 @@ const displayCallback = (arr) => {
77

88
function firstItem(arr, cb) {
99
// firstItem passes the first item of the given array to the callback function.
10-
return cb(arr[0]);
10+
cb(arr[0]);
1111
}
1212

1313
firstItem(items, displayCallback);
1414

1515
function getLength(arr, cb) {
1616
// getLength passes the length of the array into the callback.
17-
return cb(arr.length);
17+
cb(arr.length);
1818
}
1919

2020
getLength(items, displayCallback);
2121

2222

2323
function last(arr, cb) {
2424
// last passes the last item of the array into the callback.
25-
return cb(arr[arr.length - 1]);
25+
cb(arr[arr.length - 1]);
2626
}
2727

2828
last(items, displayCallback);
2929

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

3535
sumNums(3, 4, displayCallback);
3636

3737
function multiplyNums(x, y, cb) {
3838
// multiplyNums multiplies two numbers and passes the result to the callback.
39-
return cb(x * y);
39+
cb(x * y);
4040
}
4141

4242
multiplyNums(3, 4, displayCallback);
@@ -45,9 +45,9 @@ function contains(item, list, cb) {
4545
// contains checks if an item is present inside of the given array/list.
4646
// Pass true to the callback if it is, otherwise pass false.
4747
if(list.includes(item)){
48-
return cb(true);
48+
cb(true);
4949
}else{
50-
return cb(false);
50+
cb(false);
5151
}
5252
}
5353

@@ -59,16 +59,16 @@ contains("stick", items, displayCallback);
5959
function removeDuplicates(array, cb) {
6060
let newArr = [];
6161
array.forEach((element) => {
62-
if (newArr.includes(element)){
63-
console.log(`Duplicate element: ${element} skipped`);
64-
} else {
62+
if (!newArr.includes(element)){
6563
newArr.push(element);
64+
} else {
65+
console.log(`Duplicate element: ${element} skipped`);
6666
}
6767
});
6868
// removeDuplicates removes all duplicate values from the given array.
6969
// Pass the duplicate free array to the callback function.
7070
// Do not mutate the original array.
71-
return cb(array);
71+
cb(newArr);
7272
}
7373

7474
removeDuplicates(items, displayCallback);

‎assignments/function-conversion.js‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
// Take the commented ES5 syntax and convert it to ES6 arrow Syntax
1+
//Take the commented ES5 syntax and convert it to ES6 arrow Syntax
22

3-
// let myFunction = function () {};
3+
let myFunction = () => {};
44

5-
// let anotherFunction = function (param) {
6-
// return param;
7-
// };
5+
let anotherFunction = (param) => {
6+
return param;
7+
};
88

9-
// let add = function (param1, param2) {
10-
// return param1 + param2;
11-
// };
12-
// add(1,2);
9+
let add = (param1, param2) => {
10+
return param1 + param2;
11+
};
12+
add(1,2);
1313

14-
// let subtract = function (param1, param2) {
15-
// return param1 - param2;
16-
// };
17-
// subtract(1,2);
14+
let subtract = (param1, param2) => {
15+
return param1 - param2;
16+
};
17+
subtract(1,2);
1818

19-
// exampleArray = [1,2,3,4];
20-
// const triple = exampleArray.map(function (num) {
21-
// return num * 3;
22-
// });
23-
// console.log(triple);
19+
exampleArray = [1,2,3,4];
20+
const triple = exampleArray.map((num) => {
21+
return num * 3;
22+
});
23+
console.log(triple);

0 commit comments

Comments
 (0)