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
67 changes: 61 additions & 6 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,83 @@ 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 = [];
//normal way because I don't understand this still:
let firstName = [];
let lastName = [];
for (let i= 0; i < runners.length; i++){
firstName.push(runners[i].first_name);
lastName.push(runners[i].last_name);
fullName.push(''+firstName[i]+ '' + ' ' +lastName[i]+ '');
//redundant could just push like this:
//fullName.push(''+runners[i].first_name+ ''+' '+runners[i].last_name+'');
}
console.log('\n-----------------');
console.log(firstName);
console.log('\n-----------------');
console.log(lastName);
console.log('\n-------- initial attempt---------');
console.log(fullName);
// now with more 'advanced' method foreach:
runners.forEach(function(i){
fullName.push(''+i.first_name+ ''+' '+i.last_name+'')})
console.log('\n-------- forEach---------'); //becasue I like the idea of a kinda markdown in console =D why not lemme be happy
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 = [];
let allCaps = runners.map((i)=>{
return i.first_name.toUpperCase();
});
console.log('\n-------- map ---------');
console.log(allCaps);

// ==== Challenge 3: Use .filter() ====
// The large shirts won't be available for the event due to an ordering issue. Get a list of runners with large sized shirts so they can choose a different size. Return an array named largeShirts that contains information about the runners that have a shirt size of L and log the result
let largeShirts = [];
let largeShirts = runners.filter((shirts) => {
return shirts.shirt_size === "L";
}) ;
console.log('\n-------- filter ---------');
console.log(largeShirts);

// ==== Challenge 4: Use .reduce() ====
// The donations need to be tallied up and reported for tax purposes. Add up all the donations into a ticketPriceTotal array and log the result
let ticketPriceTotal = [];
console.log('\n-------- reduce ---------');
let ticketPriceTotal = runners.reduce(/*can ignore function callback declarion*/(/* parameters of the callbak*/ total, individual) =>{
//and then you just add then lol?
return total + individual.donation;
}, /* missed inital value was getting back the list of objects refering to donation*/ 0);
console.log(ticketPriceTotal);

// ==== Challenge 5: Be Creative ====
// Now that you have used .forEach(), .map(), .filter(), and .reduce(). I want you to think of potential problems you could solve given the data set and the 5k fun run theme. Try to solve 3 unique problems using one or many of the array methods listed above.

// Problem 1
// Problem 1 let's get the company names!

// Problem 2
let company = runners.filter((comp) => {
return comp.company_name === "Oyope";
}) ;
console.log(company);

// Problem 3
// Problem 2 now let's try to just get the company names if their shirt is M
console.log('\n-------- compshirt ---------');
let shirtcomp = runners.filter((shirt) => {
if (shirt.shirt_size === "M") {
return runners.company_name;
}
}) ;
console.log(shirtcomp);

// Problem 3 something random involving a combo let's sum the ids after filtering for now

let ages = runners
//FIRST FILTER FOR SHIRT SIZE
.filter((a) => {
return a.shirt_size === 'M';
console.log(a)
}).map((a) => {
return a.id * 7
}).reduce((sum, a) => {
return sum + a.id;
});
console.log('\n-------- ages ---------');
console.log(ages);
38 changes: 31 additions & 7 deletions assignments/closure.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
// ==== Challenge 1: Write your own closure ====
// Write a simple closure of your own creation. Keep it simple!
let hello = 'hello'

function default(){
let n = 'world'
return `Hello ${hello}`
}


// ==== Challenge 2: Create a counter function ====
const counter = () => {
// Return a function that when invoked increments and returns a counter variable.
};
// Example usage: const newCounter = counter();
// newCounter(); // 1
// newCounter(); // 2

function counter(){
let n = 0
return {increment:function(){
n += 1;
}
}
}
const newCounter = counter();
newCounter.increment() //1



// ==== Challenge 3: Create a counter function with an object that can increment and decrement ====
const counterFactory = () => {
let n = 0
return {
increment:function(){
n += 1;
},
decrement:function(){
n -= 1;
},
}
}

const yetAnotherCounterFactory = counterFactory();
yetAnotherCounterFactory.increment()
yetAnotherCounterFactory.decrement()
// 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.
};
25 changes: 10 additions & 15 deletions assignments/function-conversion.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
// Take the commented ES5 syntax and convert it to ES6 arrow Syntax

// let myFunction = function () {};
let myFunction = a => {`a`;}

// let anotherFunction = function (param) {
// return param;
// };
let anotherFunction = param => {
`param;` //I sitll don't get this template literal stuff or what the hell is the point. Why are there a million ways of doing the same thing? 2 would suffice no?
};

// let add = function (param1, param2) {
// return param1 + param2;
// };
// add(1,2);
let add = (param1, param2) => { return param1 + param2;};
add(1,2);

let subtract = function (param1, param2) {
return param1 - param2;
let subtract = (param1, param2) => {return param1 - param2;
};
subtract(1,2); //?
console.log(subtract(1,2));

exampleArray = [1,2,3,4];
// const triple = exampleArray.map(function (num) {
// return num * 3;
// });
// console.log(triple);
const triple = exampleArray.map(num => num * 3);
console.log(triple);