Skip to content

Commit a44f4a9

Browse files
committed
Initial commits for JS-II
- Added gitignore - Updated Readme - Added array-methods.js - Added closure.js
0 parents  commit a44f4a9

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# JavaScript - II
2+
With some basic JavaScript principles we can now expand our skills out even further by exploring array methods like: `.forEach()`, `.map()`, `.reduce()`, and `.filter()`. We can also look at how closures have a large impact on how we write JavaScript.
3+
4+
## Assignment Description
5+
6+
* Fork/Clone this repository.
7+
* Complete all the exercises as described inside each assignment file.
8+
* Use `console.log()` statements to check to see if your code does what it is supposed to do.
9+
* To test your `console` statements you can either run `node /assignments/<fileName>` and see what prints in your terminal. You can also use an online tool like `JSBin`, `REPL.it`, `JSFiddle` or even your `Chrome developer console`.
10+
* Once you finish the exercises in each file, commit your code, and push it to your fork.
11+
12+
### Array Methods
13+
Use .forEach(), .map(), .filter(), and .reduce() to loop over an array with 50 objects in it. The [array-methods.js](assignments/array-methods.js) file contains several challenges built around a fund rasising 5k fun run event.
14+
15+
* Read the instructions found within the file carefully to finish the challenges.
16+
* The last challenge is to come up with 3 problems to solve and then build a solution for them using any of the array methods listed above.
17+
* Share one of your favorite problem/solutions in your team meeting.
18+
* Complete each challenge presented before moving on to closure.
19+
20+
### Closures
21+
The [closure.js](assignments/closure.js) assignment showcases how variables can be used outside of functions to store state using closure.
22+
23+
* Complete each challenge.

assignments/array-methods.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// A local community center is holding a fund rasising 5k fun run and has invited 50 small businesses to make a small donation on their behalf for some much needed updates to their facilities. Each business has assigned a representative to attend the event along with a small donation.
2+
3+
// Scroll to the bottom of the list to use some advanced array methods to help the event director gather some information from the businesses.
4+
5+
const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"[email protected]","shirt_size":"2XL","company_name":"Divanoodle","donation":75},
6+
{"id":2,"first_name":"Whitaker","last_name":"Ierland","email":"[email protected]","shirt_size":"2XL","company_name":"Wordtune","donation":148},
7+
{"id":3,"first_name":"Julieta","last_name":"McCloid","email":"[email protected]","shirt_size":"S","company_name":"Riffpedia","donation":171},
8+
{"id":4,"first_name":"Martynne","last_name":"Paye","email":"[email protected]","shirt_size":"XL","company_name":"Wordware","donation":288},
9+
{"id":5,"first_name":"Gussy","last_name":"Raraty","email":"[email protected]","shirt_size":"L","company_name":"Oozz","donation":291},
10+
{"id":6,"first_name":"Yule","last_name":"Tommasetti","email":"[email protected]","shirt_size":"S","company_name":"Yodo","donation":27},
11+
{"id":7,"first_name":"Kathie","last_name":"Majury","email":"[email protected]","shirt_size":"3XL","company_name":"Zoomcast","donation":261},
12+
{"id":8,"first_name":"Tanner","last_name":"Branton","email":"[email protected]","shirt_size":"2XL","company_name":"Realmix","donation":28},
13+
{"id":9,"first_name":"Sarina","last_name":"Lasham","email":"[email protected]","shirt_size":"XL","company_name":"Gigashots","donation":110},
14+
{"id":10,"first_name":"Bertie","last_name":"Lonergan","email":"[email protected]","shirt_size":"3XL","company_name":"Skinte","donation":62},
15+
{"id":11,"first_name":"Trevor","last_name":"Studd","email":"[email protected]","shirt_size":"S","company_name":"Cogidoo","donation":76},
16+
{"id":12,"first_name":"Malachi","last_name":"Okeshott","email":"[email protected]","shirt_size":"M","company_name":"DabZ","donation":91},
17+
{"id":13,"first_name":"Berget","last_name":"Logsdail","email":"[email protected]","shirt_size":"M","company_name":"Mymm","donation":9},
18+
{"id":14,"first_name":"Loise","last_name":"Rivlin","email":"[email protected]","shirt_size":"2XL","company_name":"Linktype","donation":204},
19+
{"id":15,"first_name":"Christan","last_name":"Kendall","email":"[email protected]","shirt_size":"XS","company_name":"Skinix","donation":252},
20+
{"id":16,"first_name":"Kayla","last_name":"Whitwam","email":"[email protected]","shirt_size":"2XL","company_name":"Oyope","donation":147},
21+
{"id":17,"first_name":"Heddie","last_name":"Heningam","email":"[email protected]","shirt_size":"L","company_name":"Skinix","donation":172},
22+
{"id":18,"first_name":"Mace","last_name":"Ballinger","email":"[email protected]","shirt_size":"S","company_name":"Nlounge","donation":266},
23+
{"id":19,"first_name":"Nola","last_name":"Abberley","email":"[email protected]","shirt_size":"XL","company_name":"Photospace","donation":148},
24+
{"id":20,"first_name":"Nadine","last_name":"Tresler","email":"[email protected]","shirt_size":"3XL","company_name":"Wikido","donation":292},
25+
{"id":21,"first_name":"Ulrikaumeko","last_name":"Vuittet","email":"[email protected]","shirt_size":"S","company_name":"Skinte","donation":102},
26+
{"id":22,"first_name":"Saunder","last_name":"Spennock","email":"[email protected]","shirt_size":"3XL","company_name":"Kwimbee","donation":213},
27+
{"id":23,"first_name":"Carmel","last_name":"Woffinden","email":"[email protected]","shirt_size":"S","company_name":"Rooxo","donation":137},
28+
{"id":24,"first_name":"Marielle","last_name":"Kimmel","email":"[email protected]","shirt_size":"M","company_name":"Livetube","donation":96},
29+
{"id":25,"first_name":"Brucie","last_name":"Burris","email":"[email protected]","shirt_size":"2XL","company_name":"Wordtune","donation":128},
30+
{"id":26,"first_name":"Juan","last_name":"Berzon","email":"[email protected]","shirt_size":"3XL","company_name":"Einti","donation":234},
31+
{"id":27,"first_name":"Sacha","last_name":"Olsen","email":"[email protected]","shirt_size":"2XL","company_name":"Viva","donation":190},
32+
{"id":28,"first_name":"Jamey","last_name":"O'Nolan","email":"[email protected]","shirt_size":"XL","company_name":"Skinix","donation":31},
33+
{"id":29,"first_name":"Morrie","last_name":"Rainard","email":"[email protected]","shirt_size":"XS","company_name":"Podcat","donation":52},
34+
{"id":30,"first_name":"Fidel","last_name":"Roskelly","email":"[email protected]","shirt_size":"XS","company_name":"Avavee","donation":5},
35+
{"id":31,"first_name":"Toni","last_name":"MacSweeney","email":"[email protected]","shirt_size":"M","company_name":"Jaloo","donation":82},
36+
{"id":32,"first_name":"Jessey","last_name":"Walhedd","email":"[email protected]","shirt_size":"L","company_name":"Trilia","donation":5},
37+
{"id":33,"first_name":"Karola","last_name":"Piper","email":"[email protected]","shirt_size":"3XL","company_name":"Yombu","donation":110},
38+
{"id":34,"first_name":"Marley","last_name":"Mitchenson","email":"[email protected]","shirt_size":"M","company_name":"Zoonoodle","donation":97},
39+
{"id":35,"first_name":"Marrilee","last_name":"Thrasher","email":"[email protected]","shirt_size":"XL","company_name":"Bluejam","donation":17},
40+
{"id":36,"first_name":"Tye","last_name":"Manie","email":"[email protected]","shirt_size":"L","company_name":"Kanoodle","donation":30},
41+
{"id":37,"first_name":"Charleen","last_name":"Sheering","email":"[email protected]","shirt_size":"3XL","company_name":"Jatri","donation":262},
42+
{"id":38,"first_name":"Valma","last_name":"Eynaud","email":"[email protected]","shirt_size":"XS","company_name":"Jaxbean","donation":212},
43+
{"id":39,"first_name":"Dollie","last_name":"McDarmid","email":"[email protected]","shirt_size":"S","company_name":"Kayveo","donation":74},
44+
{"id":40,"first_name":"Minna","last_name":"Hymas","email":"[email protected]","shirt_size":"XS","company_name":"Vimbo","donation":101},
45+
{"id":41,"first_name":"Jsandye","last_name":"Frend","email":"[email protected]","shirt_size":"XS","company_name":"Latz","donation":156},
46+
{"id":42,"first_name":"Yevette","last_name":"Hacket","email":"[email protected]","shirt_size":"XL","company_name":"Lazzy","donation":291},
47+
{"id":43,"first_name":"Hank","last_name":"Zebedee","email":"[email protected]","shirt_size":"L","company_name":"Gigashots","donation":241},
48+
{"id":44,"first_name":"Jodie","last_name":"Stawell","email":"[email protected]","shirt_size":"S","company_name":"Jaxspan","donation":262},
49+
{"id":45,"first_name":"Falito","last_name":"Karsh","email":"[email protected]","shirt_size":"S","company_name":"Mycat","donation":239},
50+
{"id":46,"first_name":"Reginauld","last_name":"Purselowe","email":"[email protected]","shirt_size":"L","company_name":"Jabbersphere","donation":11},
51+
{"id":47,"first_name":"Vida","last_name":"Tydd","email":"[email protected]","shirt_size":"S","company_name":"Quaxo","donation":55},
52+
{"id":48,"first_name":"Anderea","last_name":"MacGiolla Pheadair","email":"[email protected]","shirt_size":"2XL","company_name":"Kwimbee","donation":214},
53+
{"id":49,"first_name":"Bel","last_name":"Alway","email":"[email protected]","shirt_size":"S","company_name":"Voolia","donation":107},
54+
{"id":50,"first_name":"Shell","last_name":"Baine","email":"[email protected]","shirt_size":"M","company_name":"Gabtype","donation":171}];
55+
56+
// ==== 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.
58+
let fullName = [];
59+
console.log(fullName);
60+
61+
// ==== Challenge 2: Use .map() ====
62+
// 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);
65+
66+
// ==== Challenge 3: Use .filter() ====
67+
// 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);
70+
71+
// ==== Challenge 4: Use .reduce() ====
72+
// 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);
75+
76+
// ==== Challenge 5: Be Creative ====
77+
// 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.
78+
79+
// Problem 1
80+
81+
// Problem 2
82+
83+
// Problem 3

assignments/closure.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// ==== Challenge 1: Write your own closure ====
2+
// Write a simple closure of your own creation. Keep it simple!
3+
4+
5+
// ==== Challenge 2: Create a counter function ====
6+
const counter = () => {
7+
// Return a function that when invoked increments and returns a counter variable.
8+
};
9+
// Example usage: const newCounter = counter();
10+
// newCounter(); // 1
11+
// newCounter(); // 2
12+
13+
14+
// ==== Challenge 3: Create a counter function with an object that can increment and decrement ====
15+
const counterFactory = () => {
16+
// Return an object that has two methods called `increment` and `decrement`.
17+
// `increment` should increment a counter variable in closure scope and return it.
18+
// `decrement` should decrement the counter variable and return it.
19+
};

0 commit comments

Comments
 (0)