Skip to content

Commit 7a4cec7

Browse files
authored
Merge pull request #1 from ConConRob/Connor-Robertson
Connor robertson
2 parents afae86b + 4e05653 commit 7a4cec7

4 files changed

Lines changed: 98 additions & 20 deletions

File tree

‎assignments/array-methods.js‎

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,49 @@ 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-
console.log(fullName);
59+
runners.forEach(function (runner) {
60+
fullName.push(`${runner.first_name} ${runner.last_name}`);
61+
});
62+
//console.log(fullName);
6063

6164
// ==== Challenge 2: Use .map() ====
6265
// 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
63-
let allCaps = [];
64-
console.log(allCaps);
66+
let allCaps = runners.map(function(runner){
67+
return runner.first_name.toUpperCase();
68+
})
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
68-
let largeShirts = [];
69-
console.log(largeShirts);
73+
let largeShirts = runners.filter(function (runner) {
74+
return runner.shirt_size==="L";
75+
});
76+
//console.log(largeShirts);
7077

7178
// ==== Challenge 4: Use .reduce() ====
7279
// 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
73-
let ticketPriceTotal = [];
74-
console.log(ticketPriceTotal);
80+
let ticketPriceTotal = runners.reduce(function(acc, runner){
81+
return acc+runner.donation;
82+
},0);
83+
//console.log(ticketPriceTotal);
7584

7685
// ==== Challenge 5: Be Creative ====
7786
// 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.
7887

79-
// Problem 1
88+
// Problem 1 I want a email list that has the first name, last name, email and company name
89+
const emailList = runners.map(function(runner){
90+
return {
91+
first_name: runner.first_name,
92+
last_name: runner.last_name,
93+
company_name: runner.company_name,
94+
email: runner.email
95+
};
96+
})
97+
//console.log(emailList)
98+
// Problem 2 A list of donation over 200
99+
const highDonor = runners.filter(runner => runner.donation>=200);
100+
//console.log(highDonor);
101+
// Problem 3 all runners that first names start with C. This organizer 's name starts with C so he likes it when someone's name starts with C. He wants to give a headstart to these people so get him a list.
80102

81-
// Problem 2
82-
83-
// Problem 3
103+
const CRunners = runners.filter(runner=>runner.first_name[0]==="C").map(runner => `${runner.first_name} ${runner.last_name}`);
104+
//console.log(CRunners);

‎assignments/callbacks.js‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,51 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2020
});
2121
2222
*/
23-
23+
//console.logs whatever it is given
24+
function logger(logMe){
25+
console.log(logMe);
26+
}
2427

2528
function getLength(arr, cb) {
2629
// getLength passes the length of the array into the callback.
30+
cb(arr.length);
2731
}
32+
//getLength(items, logger);
2833

2934
function last(arr, cb) {
3035
// last passes the last item of the array into the callback.
36+
cb(arr[arr.length-1]);
3137
}
38+
//last(items, logger);
3239

3340
function sumNums(x, y, cb) {
3441
// sumNums adds two numbers (x, y) and passes the result to the callback.
42+
cb(x+y);
3543
}
44+
//sumNums(3, 2, logger);
3645

3746
function multiplyNums(x, y, cb) {
3847
// multiplyNums multiplies two numbers and passes the result to the callback.
48+
cb(x*y);
3949
}
50+
//multiplyNums(3, 5, logger);
4051

4152
function contains(item, list, cb) {
4253
// contains checks if an item is present inside of the given array/list.
4354
// Pass true to the callback if it is, otherwise pass false.
55+
cb(list.includes(item));
4456
}
57+
//contains("Gum", items, logger);
4558

4659
/* STRETCH PROBLEM */
4760

4861
function removeDuplicates(array, cb) {
4962
// removeDuplicates removes all duplicate values from the given array.
5063
// Pass the duplicate free array to the callback function.
5164
// Do not mutate the original array.
65+
cb(array.filter( (obj, i )=> array.indexOf(obj) ===i
66+
));
5267
}
68+
//items.push(...items);
69+
//console.log(items);
70+
//removeDuplicates(items, logger);

‎assignments/closure.js‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
// ==== Challenge 1: Write your own closure ====
22
// Write a simple closure of your own creation. Keep it simple!
33

4+
let outside ="i am outsite the function";
5+
function closure() {
6+
let inside = "I am inside this function";
7+
console.log(outside);
8+
console.log(inside) ;
9+
};
10+
//console.dir(closure);
411

512
// ==== Challenge 2: Create a counter function ====
613
const counter = () => {
714
// Return a function that when invoked increments and returns a counter variable.
15+
let count =0;
16+
17+
return function () {
18+
//console.log(count);
19+
return count++;
20+
}
821
};
22+
const counterOne = counter();
23+
//counterOne();
24+
//counterOne();
25+
//counterOne();
26+
//counterOne();
27+
928
// Example usage: const newCounter = counter();
1029
// newCounter(); // 1
1130
// newCounter(); // 2
@@ -14,7 +33,23 @@ const counter = () => {
1433

1534
// ==== Challenge 3: Create a counter function with an object that can increment and decrement ====
1635
const counterFactory = () => {
36+
let count=0;
1737
// Return an object that has two methods called `increment` and `decrement`.
18-
// `increment` should increment a counter variable in closure scope and return it.
19-
// `decrement` should decrement the counter variable and return it.
38+
return {
39+
// `increment` should increment a counter variable in closure scope and return it.
40+
increment: function() {
41+
count++;
42+
return count;
43+
},
44+
// `decrement` should decrement the counter variable and return it.
45+
decrement: function() {
46+
count--
47+
return count;
48+
},
49+
//checks what the counter is at
50+
check: function() {
51+
return count;
52+
}
53+
}
2054
};
55+
const counterF = counterFactory();
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
// Take the commented ES5 syntax and convert it to ES6 arrow Syntax
22

33
// let myFunction = function () {};
4-
4+
let myFunction = () => {};
55
// let anotherFunction = function (param) {
66
// return param;
77
// };
8-
8+
let anotherFunction = param => param;
99
// let add = function (param1, param2) {
1010
// return param1 + param2;
1111
// };
1212
// add(1,2);
13-
13+
let add = (param1, param2)=> param1+param2;
14+
//console.log(add(1,2));
1415
// let subtract = function (param1, param2) {
1516
// return param1 - param2;
1617
// };
1718
// subtract(1,2);
18-
19-
// exampleArray = [1,2,3,4];
19+
let subtract = (param1, param2) => param1 - param2;
20+
//console.log(subtract(1,2));
21+
exampleArray = [1,2,3,4];
2022
// const triple = exampleArray.map(function (num) {
2123
// return num * 3;
2224
// });
23-
// console.log(triple);
25+
// console.log(triple);
26+
const triple = exampleArray.map(num => num*3);
27+
console.log(triple);

0 commit comments

Comments
 (0)