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
8 changes: 8 additions & 0 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ 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 = [];
for (let i = 0; i < runners.length; i++){
let combo = {};
combo.name = runners[i].first_name;
combo.lastName = runners[i].last_name;
fullName.push(combo);
combo = {};

}
console.log(fullName);

// ==== Challenge 2: Use .map() ====
Expand Down
21 changes: 21 additions & 0 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,41 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];

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

getLength (items,(itemQty) => {
console.log(itemQty);
});


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

last(items, function(lastItem) {
console.log(lastItem);
});

function sumNums(x, y, cb) {
// sumNums adds two numbers (x, y) and passes the result to the callback.
cb (x + y);
}

sumNums(5, 5, function (sum) {
console.log(sum);
});

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

multiplyNums(5, 5, function (mult) {
console.log(mult);
});

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
21 changes: 20 additions & 1 deletion assignments/closure.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
// ==== Challenge 1: Write your own closure ====
// Write a simple closure of your own creation. Keep it simple!

let myName = 'Raul';
function sayMyName() {
let lastName = 'Ortiz';
return (`My name is ${myName} ${lastName}`);
}

sayMyName();
console.log (sayMyName());

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


// ==== Challenge 2: Create a counter function ====
const counter = () => {
// Return a function that when invoked increments and returns a counter variable.
};
let count = 0;

return function () {
return ++count;
}
};

let newCounter = counter();
console.log(newCounter());
console.log(newCounter());
console.log(newCounter());

// Example usage: const newCounter = counter();
// newCounter(); // 1
// newCounter(); // 2
Expand Down