Skip to content

Commit d0e038f

Browse files
authored
Merge pull request #1 from prophen/nikema-prophet
set up git repo
2 parents bc4a039 + 52680bd commit d0e038f

File tree

4 files changed

+66
-15
lines changed

4 files changed

+66
-15
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,44 @@ With some basic JavaScript principles in hand, we can now expand our skills out
77

88
**Follow these steps to set up and work on your project:**
99

10-
* [ ] Create a forked copy of this project.
11-
* [ ] Add your project manager as collaborator on Github.
12-
* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!).
13-
* [ ] Create a new branch: git checkout -b `<firstName-lastName>`.
14-
* [ ] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
15-
* [ ] Push commits: git push origin `<firstName-lastName>`.
10+
* [x] Create a forked copy of this project.
11+
* [x] Add your project manager as collaborator on Github.
12+
* [x] Clone your OWN version of the repository (Not Lambda's by mistake!).
13+
* [x] Create a new branch: git checkout -b `<firstName-lastName>`.
14+
* [x] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
15+
* [x] Push commits: git push origin `<firstName-lastName>`.
1616

1717
**Follow these steps for completing your project.**
1818

19-
* [ ] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo). **Please don't merge your own pull request**
20-
* [ ] Add your project manager as a reviewer on the pull-request
21-
* [ ] Your project manager will count the project as complete by merging the branch back into master.
19+
* [x] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo). **Please don't merge your own pull request**
20+
* [x] Add your project manager as a reviewer on the pull-request
21+
* [x] Your project manager will count the project as complete by merging the branch back into master.
2222

2323
## Task 2: Higher Order Functions and Callbacks
2424

2525
This task focuses on getting practice with higher order functions and callback functions by giving you an array of values and instructions on what to do with that array.
2626

27-
* [ ] Review the contents of the [callbacks.js](assignments/callbacks.js) file. Notice you are given an array at the top of the page. Use that array to aid you with your functions.
27+
* [x] Review the contents of the [callbacks.js](assignments/callbacks.js) file. Notice you are given an array at the top of the page. Use that array to aid you with your functions.
2828

2929
* [ ] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first.
3030

3131
## Task 3: Array Methods
3232

3333
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 fundraising 5K fun run event.
3434

35-
* [ ] Review the contents of the [array-methods.js](assignments/array-methods.js) file.
35+
* [x] Review the contents of the [array-methods.js](assignments/array-methods.js) file.
3636

37-
* [ ] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first.
37+
* [x] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first.
3838

39-
* [ ] Notice the last three problems are up to you to create and solve. This is an awesome opportunity for you to push your critical thinking about array methods, have fun with it.
39+
* [x] Notice the last three problems are up to you to create and solve. This is an awesome opportunity for you to push your critical thinking about array methods, have fun with it.
4040

4141
## Task 4: Closures
4242

4343
We have learned that closures allow us to access values in scope that have already been invoked (lexical scope).
4444

4545
**Hint: Utilize debugger statements in your code in combination with your developer tools to easily identify closure values.**
4646

47-
* [ ] Review the contents of the [closure.js](assignments/closure.js) file.
47+
* [x] Review the contents of the [closure.js](assignments/closure.js) file.
4848
* [ ] Complete the problems provided to you but skip over stretch problems until you are complete with every other JS file first.
4949

5050
## Stretch Goals

assignments/array-methods.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,51 @@ 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+
runners.forEach( runner => fullName.push(`${runner.first_name} ${runner.last_name}`))
5960
console.log(fullName);
6061

62+
6163
// ==== Challenge 2: Use .map() ====
6264
// 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
6365
let allCaps = [];
66+
allCaps = runners.map(runner => runner.first_name.toUpperCase())
6467
console.log(allCaps);
6568

6669
// ==== Challenge 3: Use .filter() ====
6770
// 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
6871
let largeShirts = [];
72+
largeShirts = runners.filter(runner => runner.shirt_size === 'L')
6973
console.log(largeShirts);
7074

7175
// ==== Challenge 4: Use .reduce() ====
7276
// 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
7377
let ticketPriceTotal = [];
78+
ticketPriceTotal = runners.reduce((acc, runner) => acc += runner.donation, 0)
7479
console.log(ticketPriceTotal);
7580

7681
// ==== Challenge 5: Be Creative ====
7782
// 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.
7883

7984
// Problem 1
85+
// Create a list of runners with their names and email addresses to send out reminders before the race.
86+
87+
const emailList = runners.map(runner => {
88+
const nameEmailPair = {};
89+
nameEmailPair.name = `${runner.first_name} ${runner.last_name}`
90+
nameEmailPair.email = runner.email
91+
92+
return nameEmailPair
93+
})
94+
console.log(emailList);
8095

8196
// Problem 2
97+
// List all of the companies represented in the race
98+
99+
const companyNames = runners.map(runner => runner.company_name)
100+
console.log(companyNames);
101+
102+
// Problem 3
103+
// Find every runner who raised less than $20 and bug them to get more money
82104

83-
// Problem 3
105+
const slackers = runners.filter(runner => runner.donation < 20)
106+
console.log(slackers)

assignments/callbacks.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,47 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
2424
2525
*/
2626

27+
function showResult(result) {
28+
console.log('Callback Result:', result)
29+
}
2730

2831
function getLength(arr, cb) {
2932
// getLength passes the length of the array into the callback.
33+
return cb(arr.length)
3034
}
35+
getLength(items, showResult)
3136

3237
function last(arr, cb) {
3338
// last passes the last item of the array into the callback.
39+
return cb(arr[arr.length -1])
3440
}
41+
last(items, showResult)
3542

3643
function sumNums(x, y, cb) {
3744
// sumNums adds two numbers (x, y) and passes the result to the callback.
45+
return cb(x + y)
3846
}
47+
sumNums(2, 20, showResult)
3948

4049
function multiplyNums(x, y, cb) {
4150
// multiplyNums multiplies two numbers and passes the result to the callback.
51+
return cb(x * y)
4252
}
53+
multiplyNums(12, 2, showResult)
4354

4455
function contains(item, list, cb) {
4556
// contains checks if an item is present inside of the given array/list.
4657
// Pass true to the callback if it is, otherwise pass false.
58+
if (list.includes(item)) {
59+
return cb(true)
60+
} else {
61+
return cb(false)
62+
}
4763
}
4864

65+
contains('yo-yo',items,showResult)
66+
contains('bicycle', items, showResult)
67+
4968
/* STRETCH PROBLEM */
5069

5170
function removeDuplicates(array, cb) {

assignments/closure.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
// ==== Challenge 1: Write your own closure ====
22
// Write a simple closure of your own creation. Keep it simple!
3+
function sayHello (greeting, name) {
4+
function makeGreeting() {
5+
console.log(greeting + ' ' + name + ' from makeGreeting()')
6+
}
7+
return makeGreeting();
8+
}
9+
sayHello('Hello','Nikema');
10+
sayHello('Hi','Mark')
311

412

513
/* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */
@@ -8,6 +16,7 @@
816
// ==== Challenge 2: Create a counter function ====
917
const counter = () => {
1018
// Return a function that when invoked increments and returns a counter variable.
19+
1120
};
1221
// Example usage: const newCounter = counter();
1322
// newCounter(); // 1

0 commit comments

Comments
 (0)