Skip to content

Commit bcf46e9

Browse files
committed
"MVP Complete"
1 parent afae86b commit bcf46e9

File tree

3 files changed

+121
-11
lines changed

3 files changed

+121
-11
lines changed

assignments/array-methods.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,46 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
5454
{"id":50,"first_name":"Shell","last_name":"Baine","email":"[email protected]","shirt_size":"M","company_name":"Gabtype","donation":171}];
5555

5656
// ==== Challenge 1: Use .forEach() ====
57-
// 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.
57+
// 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.
5858
let fullName = [];
59-
console.log(fullName);
59+
// runners.foreach(` ${ runners[i]["first_name"] } ${ runners[i]["last_name"] }`);
60+
61+
// runners.foreach(fullName.push(runners[i].first_name + " " + runners[i].last_name ));
62+
//
63+
// console.log(fullName);
6064

6165
// ==== Challenge 2: Use .map() ====
6266
// 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
6367
let allCaps = [];
64-
console.log(allCaps);
68+
allCaps = runners.map(function(items) {return items.first_name.toUpperCase();});
69+
console.log(allCaps);
6570

6671
// ==== Challenge 3: Use .filter() ====
6772
// 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
6873
let largeShirts = [];
74+
largeShirts = runners.filter((list) => {return list.shirt_size === "L" ;});
6975
console.log(largeShirts);
7076

7177
// ==== Challenge 4: Use .reduce() ====
7278
// 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
7379
let ticketPriceTotal = [];
80+
ticketPriceTotal = runners.reduce((total, next) => {return total + next.donation ;});
7481
console.log(ticketPriceTotal);
7582

7683
// ==== Challenge 5: Be Creative ====
7784
// 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 create and then solve 3 unique problems using one or many of the array methods listed above.
7885

79-
// Problem 1
86+
// Problem 1 - MAKE A NICKNAME FOR EACH CONTESTEANT USING THIER FIRST NAM AND SHIRT SIZE.
87+
let nickname =[];
88+
nickname = runners.map(items.first_name.toUpperCase.concat(items.shirt_size));
89+
console.log(nickname);
8090

81-
// Problem 2
91+
// Problem 2 - MAKE A LIST OF THE T DONATIONS IN ORDER OF MOST TO LEAST.
92+
let best_givers = [];
93+
best_givers = runners.map(function(items) => {`${items.donation}, ${items.first_name}, ${items.last_name}`});
94+
// sort numbers function...
8295

83-
// Problem 3
96+
// Problem 3 -
97+
let contact_list = [];
98+
contact_list = runners.map(items.email);
99+
console.log(contact_list);

assignments/callbacks.js

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

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

5-
/*
5+
/*
6+
7+
//Given this problem:
68
7-
//Given this problem:
8-
99
function firstItem(arr, cb) {
1010
// firstItem passes the first item of the given array to the callback function.
1111
}
@@ -24,24 +24,87 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2424

2525
function getLength(arr, cb) {
2626
// getLength passes the length of the array into the callback.
27+
let outPut = cb(arr);
28+
return outPut;
29+
}
30+
function callback( arr ){
31+
console.log(arr.length);
32+
return arr.length;
2733
}
2834

35+
getLength(items, callback);
36+
37+
38+
2939
function last(arr, cb) {
3040
// last passes the last item of the array into the callback.
41+
let output = cb(arr[arr.length -1]);
42+
return output;
3143
}
3244

33-
function sumNums(x, y, cb) {
45+
function callback0(arr) {
46+
console.log();
47+
return console.log()
48+
}
49+
50+
last( items , callback0);
51+
52+
// function callback( arr ){
53+
// console.log(arr.length);
54+
// return arr.length;
55+
// }
56+
// function callback1(){
57+
// console.log(
58+
// return output;
59+
// }
60+
61+
last(items,callback0);
62+
63+
64+
function sumNums(x, y) {
3465
// sumNums adds two numbers (x, y) and passes the result to the callback.
66+
let output = (x + y);
67+
return outPut;
3568
}
3669

37-
function multiplyNums(x, y, cb) {
70+
publishSum(sumNums()) {
71+
let pub = console.log(sumNums());
72+
return pub;
73+
}
74+
75+
publishSum(sumNums(10,20));
76+
77+
function multiplyNums(x, y) {
3878
// multiplyNums multiplies two numbers and passes the result to the callback.
79+
let output = ( x * y );
80+
return output;
81+
}
82+
83+
function publishMul(multiplyNums){
84+
return console.log(multiplyNums);
3985
}
4086

87+
publishMul(multiplyNums(4,3));
88+
89+
90+
91+
4192
function contains(item, list, cb) {
93+
tOrF = [];
4294
// contains checks if an item is present inside of the given array/list.
4395
// Pass true to the callback if it is, otherwise pass false.
96+
for (let i = 0 ; i < list. length; i++){
97+
if (list[i].item. !== '') {
98+
console.log(true);
99+
tOrF.push(true);
100+
} else {
101+
console.log(false);
102+
tOrF.push(true);
103+
}
104+
}
105+
return (Callback => {return console.log(tOrF)};
44106
}
107+
contains(items,arr.length,);
45108

46109
/* STRETCH PROBLEM */
47110

assignments/closure.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
// ==== Challenge 1: Write your own closure ====
22
// Write a simple closure of your own creation. Keep it simple!
3+
function yell(name){
4+
const n = name;
5+
console.log(`Can you hear Me ${n}!!!!!!`);
6+
7+
function speak(nickName){
8+
const nn = "pebbles";
9+
console.log(` Hey, ${ nn } is your given name ${ n } , i'd never heard it before.`);
10+
11+
function whisper() {
12+
const lower = "I'm sorry for speaking so loud." ;
13+
console.log (`{lower} Hey,Would you rather me call you ${ nn } or ${ n }, i knowsome people havea preference.`)
14+
}
15+
whisper();
16+
}
17+
speak();
18+
}
19+
yell();
20+
21+
322

423

524
// ==== Challenge 2: Create a counter function ====
625
const counter = () => {
26+
let count = 0;
27+
return () => (++count);
728
// Return a function that when invoked increments and returns a counter variable.
829
};
930
// Example usage: const newCounter = counter();
1031
// newCounter(); // 1
1132
// newCounter(); // 2
33+
const newCounter = counter();
34+
console.log(newCounter())
35+
console.log(newCounter())
36+
console.log(newCounter())
37+
console.log(newCounter())
38+
console.log(newCounter())
39+
console.log(newCounter())
40+
41+
42+
1243

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

0 commit comments

Comments
 (0)