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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ With some basic JavaScript principles in hand, we can now expand our skills out

**Follow these steps to set up and work on your project:**

* [ ] Create a forked copy of this project.
* [ ] Add your team lead as collaborator on Github.
* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!).
* [ ] Create a new branch: git checkout -b `<firstName-lastName>`.
* [ ] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [ ] Push commits: git push origin `<firstName-lastName>`.
* [x] Create a forked copy of this project.
* [x] Add your team lead as collaborator on Github.
* [x] Clone your OWN version of the repository (Not Lambda's by mistake!).
* [x] Create a new branch: git checkout -b `<firstName-lastName>`.
* [x] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [x] Push commits: git push origin `<firstName-lastName>`.

**Follow these steps for completing your project.**

Expand Down
20 changes: 18 additions & 2 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,33 @@ const runners = [

// ==== 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 and populate a new array called `fullNames`. This array will contain just strings.
//let fullNames = [];
//for (let i = 0; i < runners.length; i++) {
// fullNames.push(runners[i].first_name.concat(" " + runners[i].last_name))
//}
//console.log(fullNames);

let fullNames = [];
for(let i = 0; i < runners.length; i++){
runners.forEach(function(name){
fullNames.push(runners[i].first_name.concat(" " + runners[i].last_name))
})
}
console.log(fullNames);

// ==== Challenge 2: Use .map() ====
// The event director needs to have all the runners' first names in uppercase because the director BECAME DRUNK WITH POWER. Populate an array called `firstNamesAllCaps`. This array will contain just strings.
let firstNamesAllCaps = [];
runners.map(
(name = name => {
let uppercase = name.first_name.toUpperCase();
firstNamesAllCaps.push(uppercase);
})
);
console.log(firstNamesAllCaps);

// ==== Challenge 3: Use .filter() ====
// The large shirts won't be available for the event due to an ordering issue. We need a filtered version of the runners array, containing only those runners with large sized shirts so they can choose a different size. This will be an array of objects.
let runnersLargeSizeShirt = [];
let runnersLargeSizeShirt = runners.filter(shirt => shirt.shirt_size === 'L');
console.log(runnersLargeSizeShirt);

// ==== Challenge 4: Use .reduce() ====
Expand Down
72 changes: 53 additions & 19 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,67 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
const test2 = firstItem(items, logExorbitantPrice);
console.log(test2); // "this Pencil is worth a million dollars!"
*/
//callback function
function findLength(x) {
console.log(x)
}


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

function last(arr, cb) {
// last passes the last item of the array into the callback.
}
getLength(items, findLength)

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

function multiplyNums(x, y, cb) {
// multiplyNums multiplies two numbers and passes the result to the callback.
function last(arr, cb) {
return cb(arr[3])
}

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.
}
last(items, findLast)

/* STRETCH PROBLEM */
//addUp is callback

function removeDuplicates(array, cb) {
// removeDuplicates removes all duplicate values from the given array.
// Pass the duplicate free array to the callback function.
// Do not mutate the original array.
}
//function callback is being passed into
function sumNums(x, y, callback) {
return callback(x + y);
}

sumNums(3, 4, function(addUp){
console.log(addUp)
})

function multiplyNums(x, y, callback) {
return callback(x * y);
}

multiplyNums(50, 666, function(multiply){
console.log(multiply) ;
})

function contain (item, list) {
for (let i = 0; i < list.length; i++) {
if (list[i] === item) {
return true;
} else {
return false;
}
}
}

// contains checks if an item is present inside of the given array/list.
// Pass true to the callback if it is, otherwise pass false.


contains(items, )

/* STRETCH PROBLEM */

function removeDuplicates(array, cb) {
// removeDuplicates removes all duplicate values from the given array.
// Pass the duplicate free array to the callback function.
// Do not mutate the original array.
}
26 changes: 26 additions & 0 deletions assignments/closure.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
// Keep it simple! Remember a closure is just a function
// that manipulates variables defined in the outer scope.
// The outer scope can be a parent function, or the top level of the script.
function ownClosure() {
let name = "Najja O'Connor";

function alertDisplay() {
console.log("My name is" + ":" + " " + name);
}
return alertDisplay;
}

let myFunction = ownClosure();
myFunction();

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

Expand All @@ -12,11 +22,19 @@
const counterMaker = () => {
// IMPLEMENTATION OF counterMaker:
// 1- Declare a `count` variable with a value of 0. We will be mutating it, so declare it using `let`!
let count = 0;
// 2- Declare a function `counter`. It should increment and return `count`.
// NOTE: This `counter` function, being nested inside `counterMaker`,
// "closes over" the `count` variable. It can "see" it in the parent scope!
function counter() {
return count++;
}
// 3- Return the `counter` function.
return counter;
};
counter() = counterMaker();
myCounter();
myCounter();
// Example usage: const myCounter = counterMaker();
// myCounter(); // 1
// myCounter(); // 2
Expand All @@ -27,7 +45,15 @@ const counterMaker = () => {

// ==== Challenge 4: Create a counter function with an object that can increment and decrement ====
const counterFactory = () => {
increment: function increment(num) {
let counter = 0;
return num++;
}
decrement: function decrement (num) {
return counter--;
}
// Return an object that has two methods called `increment` and `decrement`.
// `increment` should increment a counter variable in closure scope and return it.
// `decrement` should decrement the counter variable and return it.
};
console.log(counterFactory());