Skip to content

Commit 4927ad6

Browse files
authored
Merge pull request #1 from t-tullis/terrell-tullis
Finished Challenges
2 parents afae86b + d691b11 commit 4927ad6

File tree

3 files changed

+115
-4
lines changed

3 files changed

+115
-4
lines changed

assignments/array-methods.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,73 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
5656
// ==== Challenge 1: Use .forEach() ====
5757
// 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+
const runnerNames = runners.forEach( runner => {
60+
fullName.push(`Name: ${runner.first_name} ${runner.last_name}`)
61+
});
62+
5963
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 = [];
68+
const runnerFirstName = runners.map(firstName => {
69+
firstName = firstName.first_name;
70+
allCaps.push(firstName.toUpperCase());
71+
})
6472
console.log(allCaps);
6573

6674
// ==== Challenge 3: Use .filter() ====
6775
// 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
6876
let largeShirts = [];
77+
const largeShirtSize = runners.filter(runner => {
78+
if(runner.shirt_size === 'L'){
79+
largeShirts.push(runner);
80+
}
81+
})
6982
console.log(largeShirts);
7083

7184
// ==== Challenge 4: Use .reduce() ====
7285
// 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
7386
let ticketPriceTotal = [];
87+
const totalDonations = runners.reduce((total, runnerDonation) =>{
88+
return total + runnerDonation.donation;
89+
}, 0)
90+
91+
let totaledDonations = totalDonations;
92+
ticketPriceTotal.push(totaledDonations);
93+
7494
console.log(ticketPriceTotal);
7595

7696
// ==== Challenge 5: Be Creative ====
7797
// 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.
7898

7999
// Problem 1
100+
//Looking to locate runners participating from the skinix company.
101+
let skinixCompanyRunners= [];
102+
const findCompany = runners.filter(runner => {
103+
if(runner.company_name === 'Skinix'){
104+
skinixCompanyRunners.push(runner);
105+
}
106+
})
107+
console.log(skinixCompanyRunners);
80108

81109
// Problem 2
110+
//sold out of small so everyone with a small gets a medium size.
111+
let shirtSizeChanges = [];
112+
const runnerShirtSize = runners.filter(runner => {
113+
if(runner.shirt_size === 'S'){
114+
runner.shirt_size = 'M'
115+
shirtSizeChanges.push(runner);
116+
}
117+
})
118+
console.log(shirtSizeChanges);
119+
120+
// Problem 3
121+
// send emails out to all runners.
122+
123+
let allRunnerEmails = [];
82124

83-
// Problem 3
125+
const runnersEmail = runners.forEach(runner => {
126+
allRunnerEmails.push(runner.email)
127+
});
128+
console.log(allRunnerEmails);

assignments/callbacks.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Create a callback function and invoke the 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.
22

33
const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
4+
const sportsTeams = ['Giants', 'Warriors', 'Lakers', 'Knicks']
45

56
/*
67
@@ -21,28 +22,65 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2122
2223
*/
2324

25+
//higher order function for arr problems
26+
function higherOrderFunction1(arr, cb){
27+
console.log(cb(arr))
28+
}
29+
2430

2531
function getLength(arr, cb) {
2632
// getLength passes the length of the array into the callback.
33+
return arr.length;
2734
}
35+
higherOrderFunction1(items, getLength);
36+
2837

2938
function last(arr, cb) {
3039
// last passes the last item of the array into the callback.
40+
const lastItem = arr.length - 1;
41+
return arr[lastItem];
3142
}
43+
higherOrderFunction1(items, last);
3244

33-
function sumNums(x, y, cb) {
45+
//higher order function for Number problems
46+
function higherOrderFunction2(x, y, cb){
47+
console.log(cb(x, y))
48+
}
49+
50+
function sumNums(x, y) {
3451
// sumNums adds two numbers (x, y) and passes the result to the callback.
52+
return x + y;
3553
}
54+
higherOrderFunction2(4, 9, sumNums);
55+
3656

37-
function multiplyNums(x, y, cb) {
57+
58+
function multiplyNums(x, y) {
3859
// multiplyNums multiplies two numbers and passes the result to the callback.
60+
return x * y
61+
}
62+
higherOrderFunction2(4, 3, multiplyNums);
63+
64+
//Higher Order Function to check list;
65+
function higherOrderFunction3(item,list,cb){
66+
console.log(cb(item, list))
3967
}
4068

41-
function contains(item, list, cb) {
69+
function contains(item,list) {
4270
// contains checks if an item is present inside of the given array/list.
4371
// Pass true to the callback if it is, otherwise pass false.
72+
for(let i = 0; i < list.length; i++){
73+
if(item.toLowerCase() === list[i].toLowerCase()){
74+
return true;
75+
}
76+
}
77+
return false;
4478
}
4579

80+
higherOrderFunction3('yo-yo',items, contains)
81+
higherOrderFunction3('giants',sportsTeams, contains)
82+
83+
4684
/* STRETCH PROBLEM */
4785

4886
function removeDuplicates(array, cb) {

assignments/closure.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
// ==== Challenge 1: Write your own closure ====
22
// Write a simple closure of your own creation. Keep it simple!
3+
function name(first,last){
4+
const fullName = `${first} ${last}`;
5+
console.log(`My full name is: ${fullName}`);
36

7+
function time(time){
8+
const currentTime = time;
9+
console.log(`The current time is ${time}`);
10+
11+
function together(){
12+
console.log(`My name is ${fullName} and the time is ${time}`);
13+
}
14+
together();
15+
}
16+
time('2:12PM');
17+
}
18+
name('Terrell', 'Tullis');
419

520
// ==== Challenge 2: Create a counter function ====
621
const counter = () => {
22+
let startCounter = 0;
723
// Return a function that when invoked increments and returns a counter variable.
24+
console.log(startCounter);
25+
const newCounter = () =>{
26+
return ++startCounter;
27+
}
28+
console.log(newCounter());
29+
console.log(newCounter());
30+
console.log(newCounter());
31+
console.log(newCounter());
32+
console.log(newCounter());
33+
console.log(newCounter());
834
};
35+
counter();
36+
937
// Example usage: const newCounter = counter();
1038
// newCounter(); // 1
1139
// newCounter(); // 2

0 commit comments

Comments
 (0)