Skip to content

Trevor thompson #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bf193e9
First commit pushing ReadMe changes
earthboundtrev Jun 28, 2019
3ff6c6f
First attempt a closure
earthboundtrev Jun 28, 2019
f6d1cd6
Fixed my previous commit because there was an infinite loop in there
earthboundtrev Jun 28, 2019
e7aeeb3
Attempts to work on callback functions
earthboundtrev Jun 29, 2019
9beb717
Pushed forEach solution
earthboundtrev Jun 29, 2019
b93bc08
I pushed some solutions to the array methods
earthboundtrev Jun 29, 2019
8f6a6c6
pushing broken .reduce() function to access it on different Computer
earthboundtrev Jul 8, 2019
7b282da
attempt at .reduce() using arrow notation
earthboundtrev Jul 8, 2019
f15ebb6
Completed Strecth Activity for array methods
earthboundtrev Jul 9, 2019
836424e
Attempted answer to callback stretch problem
earthboundtrev Jul 9, 2019
11bd43d
Working on Closure stretch now
earthboundtrev Jul 9, 2019
fc9c5dd
Revised code from this exercise after completing 1:1
earthboundtrev Jul 10, 2019
96e0929
Modified Code for Callback functions to demonstrate understanding of …
earthboundtrev Jul 10, 2019
546781d
I modified my array-methods to use array notation
earthboundtrev Jul 15, 2019
2deb1a8
Refactored code to use arrow functions
earthboundtrev Jul 16, 2019
2dc0e85
Refactored some code to make it look better
earthboundtrev Jul 16, 2019
7bdfed5
Counter Strecth Function now properly increments, but doesn't output …
earthboundtrev Jul 16, 2019
1d5fabd
Attempt stretch assignment
earthboundtrev Sep 6, 2019
cca09d6
Refactored closure.js assignment to fully meet stretch goals
Sep 7, 2019
7ad98b2
Refactored closure.js assignment to fully meet stretch goals
Sep 7, 2019
737756f
Updating code
Sep 10, 2019
fb22df1
Refactored code to use javascript string notation for readability
Sep 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5502
}
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ With some basic JavaScript principles in hand, we can now expand our skills out

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

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

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

Expand All @@ -24,7 +24,7 @@ With some basic JavaScript principles in hand, we can now expand our skills out

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.

* [ ] 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.
* [] 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.

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

Expand Down
55 changes: 51 additions & 4 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,75 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
// ==== Challenge 1: Use .forEach() ====
// 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.
let fullName = [];

runners.forEach(item => {

fullName.push(`First Name: ${item.first_name} Last Name: ${item.last_name}`);

});

console.log(fullName);


// ==== Challenge 2: Use .map() ====
// 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
let allCaps = [];
let allCaps = runners.map(item => {

return (item.first_name.toUpperCase());

//allCaps.push(item.first_name.toUpperCase());
});

console.log(allCaps);

// ==== Challenge 3: Use .filter() ====
// 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
let largeShirts = [];
let largeShirts = runners.filter(item => {

return (item.shirt_size === 'L');

})

console.log(largeShirts);

// ==== Challenge 4: Use .reduce() ====
// 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
let ticketPriceTotal = [];
console.log(ticketPriceTotal);
let total = 0;

const totalDonations = runners.reduce((total,item) => total += item.donation, 0);
console.log(totalDonations);

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

// Problem 1

let extraLargeShirts = runners.filter (item => {

return(item.shirt_size === 'XL');

});

console.log(extraLargeShirts);


// Problem 2

// Problem 3
let runnerEmailList= [];

runners.forEach (item => {

runnerEmailList.push(item.email + ' ');
})

console.log(runnerEmailList);

// Problem 3

let shrink = runners.map(item => {

return (item.first_name.toLowerCase() + ' ' + item.last_name.toLowerCase() + '!');
});

console.log(shrink);
57 changes: 53 additions & 4 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,80 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
*/


function getLength(arr, cb) {
function getLength(items, cb) {
// getLength passes the length of the array into the callback.
return cb(items.length);
}

function last(arr, cb) {
getLength(items, length => {

console.log(length);

});

function last(items, cb) {
// last passes the last item of the array into the callback.
return cb(items[items.length-1]);
}

last(items, lastItem => {

console.log(lastItem);
});

function sumNums(x, y, cb) {

return cb(x+y);
// sumNums adds two numbers (x, y) and passes the result to the callback.
}

sumNums(3, 5, numberSum =>{

console.log(numberSum);
});

function multiplyNums(x, y, cb) {
// multiplyNums multiplies two numbers and passes the result to the callback.

return cb(x*y);
}

function contains(item, list, cb) {
multiplyNums(3, 5, multiplySums => {

console.log(multiplySums);

});

/*function contains(item, list, cb) {

return cb(item, list.find(function (item)) {

// can solve this using include function, but it definitely isn't solved yet.

});
// contains checks if an item is present inside of the given array/list.
// Pass true to the callback if it is, otherwise pass false.
}
} */

/* STRETCH PROBLEM */

function removeDuplicates(array, cb) {
// removeDuplicates removes all duplicate values from the given array.
// Pass the duplicate free array to the callback function.
// Do not mutate the original array.

// I'm not sure how to test this, but the logic of it seems sound.
// I figured if I can pop of the element that is duplicated and not the one currently being tracked then the array shouldn't mess up?

newArray=array;

for(let i = 0; i < newArray.length; i++)
{
if(newarray[i] == newArray[i+1])
{
newarray.pop(newArray[i+1]);
}
}

return(newarray, cb);
}
70 changes: 64 additions & 6 deletions assignments/closure.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,79 @@
// ==== Challenge 1: Write your own closure ====
// Write a simple closure of your own creation. Keep it simple!

const lastName = 'Johnson';

function grandfather (lastName) {
const firstName = "John";
console.log(`His name is ${firstName} ${lastName}`);
son(lastName);



function son (lastName){
const firstName = "Jason";
console.log(`His name is ${firstName} ${lastName}`);
grandson(lastName);


function grandson (lastName){

const firstName = "Jacob";
console.log(`His name is ${firstName} ${lastName}`);

}
}
}
grandfather(lastName);

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


// ==== Challenge 2: Create a counter function ====
const counter = () => {


function counter () {

let countTotal = 0;

function counterIncrementer (){

return ++countTotal;
}
return counterIncrementer;

// I honestly don't understand how this works

// Return a function that when invoked increments and returns a counter variable.
};
// Example usage: const newCounter = counter();
// newCounter(); // 1
// newCounter(); // 2
const newCounter = counter();
console.log(newCounter()); // 1
console.log(newCounter()); // 2
console.log(newCounter());

// ==== Challenge 3: Create a counter function with an object that can increment and decrement ====
const counterFactory = () => {

let number = 0;

let value = {

increment: function() {
number++;
return number;
},

decrement: function() {
number--;
return number;
}

};
testFunction = value;
testFunction.increment();
testFunction.decrement();
}

// Return an object that has two methods called `increment` and `decrement`.
// `increment` should increment a counter variable in closure scope and return it.
// `decrement` should decrement the counter variable and return it.
};
// `decrement` should decrement the counter variable and return it.