Skip to content

Commit c6608e2

Browse files
committed
questions 1 and 2 on callbacks, question 1 on arrays
1 parent bc4a039 commit c6608e2

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

assignments/array-methods.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,16 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
5454
{"id":50,"first_name":"Shell","last_name":"Baine","email":"[email protected]","shirt_size":"M","company_name":"Gabtype","donation":171}];
5555

5656
// ==== Challenge 1: Use .forEach() ====
57-
// The event director needs both the first and last names of each runner for their running bibs. Combine both the first and last names into a new array called fullName.
57+
// The event director nee ds both the first and last names of each runner for their running bibs. Combine both the first and last names into a new array called fullName.
5858
let fullName = [];
59-
console.log(fullName);
59+
60+
function bibNames (runner){
61+
fullName.push(`${runner.first_name} ${runner.last_name}`)
62+
}
63+
64+
runners.forEach(bibNames)
65+
66+
// console.log(fullName);
6067

6168
// ==== Challenge 2: Use .map() ====
6269
// The event director needs to have all the runner's first names converted to uppercase because the director BECAME DRUNK WITH POWER. Convert each first name into all caps and log the result

assignments/callbacks.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,44 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2424
2525
*/
2626

27-
27+
// getLength passes the length of the array into the callback.
2828
function getLength(arr, cb) {
29-
// getLength passes the length of the array into the callback.
29+
return cb(arr.length);
3030
}
3131

32+
getLength(items, function(getLength) {console.log(getLength)})
33+
34+
35+
// last passes the last item of the array into the callback.
3236
function last(arr, cb) {
33-
// last passes the last item of the array into the callback.
37+
return cb(arr[arr.length-1]);
3438
}
3539

40+
last(items, function(last) {console.log(last)})
41+
42+
43+
// sumNums adds two numbers (x, y) and passes the result to the callback.
3644
function sumNums(x, y, cb) {
37-
// sumNums adds two numbers (x, y) and passes the result to the callback.
45+
return cb()
3846
}
3947

48+
sumNums()
49+
50+
// multiplyNums multiplies two numbers and passes the result to the callback.
4051
function multiplyNums(x, y, cb) {
41-
// multiplyNums multiplies two numbers and passes the result to the callback.
52+
53+
4254
}
4355

56+
// contains checks if an item is present inside of the given array/list.
57+
// Pass true to the callback if it is, otherwise pass false.
4458
function contains(item, list, cb) {
45-
// contains checks if an item is present inside of the given array/list.
46-
// Pass true to the callback if it is, otherwise pass false.
59+
4760
}
4861

62+
63+
// .includes
64+
4965
/* STRETCH PROBLEM */
5066

5167
function removeDuplicates(array, cb) {

0 commit comments

Comments
 (0)