Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
// ==== Challenge 1: Use .forEach() ====
// 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.
let fullName = [];
runners.forEach(name => fullName.push(`${name.first_name} ${name.last_name}`));
console.log(fullName);

// ==== Challenge 2: Use .map() ====
// 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
let allCaps = [];
runners.map(runner => allCaps.push(runner.first_name.toUpperCase()));
console.log(allCaps);

// ==== Challenge 3: Use .filter() ====
Expand Down
55 changes: 39 additions & 16 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,71 @@
// Create a callback function and invoke the function to test your work. You have been provided an example of a problem and a solution to see how this works with our items array. Study both the problem and the solution to figure out the rest of the problems.
// Create a callback function and invoke the function to test your work.
// You have been provided an example of a problem and a solution to see how this works with our items array.
// Study both the problem and the solution to figure out the rest of the problems.

const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];

/*

//Given this problem:

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

// Potential Solution:
function firstItem(arr, cb) {
return cb(arr[0]);
}
//Given this problem:

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

// Potential Solution:
function firstItem(arr, cb) {
return cb(arr[0]);
}

function myfancynicecallback(first) {
console.log(first)
}

*/

firstItem(items, myfancynicecallback);

function getLength(arr, cb) {
// getLength passes the length of the array into the callback.
return cb(arr.length);
}
getLength(items, function (length) {
console.log(length)
});

function last(arr, cb) {
// last passes the last item of the array into the callback.
return cb(arr[arr.length - 1]);
}
last(items, function (first) {
console.log(first)
});

function sumNums(x, y, cb) {
// sumNums adds two numbers (x, y) and passes the result to the callback.
return cb(x + y);
}
sumNums(10, 123, function (add) {
console.log(add)
})

function multiplyNums(x, y, cb) {
// multiplyNums multiplies two numbers and passes the result to the callback.
return cb(x * y);
}
multiplyNums(12, 12, function (multi) {
console.log(multi)
})


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.
return cb(list.includes(item) === true)
}
contains(1, [1, 2, 3, 3, 4], MyFancyCallback)
function MyFancyCallback(myBol) {
console.log(myBol)
}

/* STRETCH PROBLEM */

function removeDuplicates(array, cb) {
Expand Down