Skip to content

working on array methods #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
5 changes: 4 additions & 1 deletion assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ 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 = [];
let fullName = runners["first_name", "last_name"];
//fullName.forEach(function(element) {

//})
console.log(fullName);

// ==== Challenge 2: Use .map() ====
Expand Down
24 changes: 23 additions & 1 deletion assignments/callbacks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Create a higher order function and invoke the callback 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'];
const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum',];

/*

Expand All @@ -27,20 +27,42 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];

function getLength(arr, cb) {
// getLength passes the length of the array into the callback.
cb(items.length);
console.log(getLength);
}
// console.log(`The Length is: ${items.length}`);
// }
// getLength();

const cb = x => {
console.log("Last item is: ", x);
return x;
}
function last(arr, cb) {
// last passes the last item of the array into the callback.
return cb(arr[items.length - 1]);
}
last(items, cb);


function sumNums(x, y, cb) {
// sumNums adds two numbers (x, y) and passes the result to the callback.
cb(x + y);
}
sumNums(7, 7, answer => {
console.log(`The Answer is: ${answer}.`)
})


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

multiplyNums(7, 7, answer => {
console.log(`The answer is: ${answer}.`)
})

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.
Expand Down
5 changes: 5 additions & 0 deletions assignments/closure.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// ==== Challenge 1: Write your own closure ====
// Write a simple closure of your own creation. Keep it simple!

const minXpReached = "Level Up!"
function levelUp() {
alert(minXpReached);
}

//levelUp();
/* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */


Expand Down