Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/assignments/array-methods.js"
}
]
}
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": 5501
}
52 changes: 49 additions & 3 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,74 @@ const runners = [
// ==== 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 and populate a new array called `fullNames`. This array will contain just strings.
let fullNames = [];
runners.forEach(runner => {
fullNames.push(runner.first_name + " " + runner.last_name);
})
console.log(fullNames);

// ==== Challenge 2: Use .map() ====
// The event director needs to have all the runners' first names in uppercase because the director BECAME DRUNK WITH POWER. Populate an array called `firstNamesAllCaps`. This array will contain just strings.
let firstNamesAllCaps = [];
runners.map(runner => {
firstNamesAllCaps.push(runner.first_name.toUpperCase());
})
// runners.map(firstNamesAllCaps = )

console.log(firstNamesAllCaps);



// ==== Challenge 3: Use .filter() ====
// The large shirts won't be available for the event due to an ordering issue. We need a filtered version of the runners array, containing only those runners with large sized shirts so they can choose a different size. This will be an array of objects.
let runnersLargeSizeShirt = [];
runnersLargeSizeShirt.push(runners.filter(runners => {
return runners.shirt_size === "L";
}));

console.log(runnersLargeSizeShirt);

// ==== Challenge 4: Use .reduce() ====
// The donations need to be tallied up and reported for tax purposes. Add up all the donations and save the total into a ticketPriceTotal variable.
let ticketPriceTotal = 0;

ticketPriceTotal = runners.reduce((accumalator, runner) => {
return accumalator + runner.donation;
}, 0);

console.log(ticketPriceTotal);

// ==== 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
// Problem 1---------------------------------------------------------------------------------
let runnersLastName = [];

runners.forEach(runner => {
return runnersLastName.push(runner.last_name);
})

console.log(runnersLastName.sort());
// Problem 2---------------------------------------------------------------------------------
let companyNames = [];

companyNames.push(runners.filter(runner => {
if (runner.company_name.includes("S")){
return runner.company_name
}
return runner.company_name === "S"
}));

console.log(companyNames);

// Problem 3---------------------------------------------------------------------------------
let topDonators = [];

// Problem 2
topDonators = runners.filter(donators => {
if (donators.donation > 200){
return true;
} else {
return false;
}
});

// Problem 3
console.log(topDonators.sort((a, b) => (b.donation - a.donation)));
69 changes: 61 additions & 8 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Create a higher order function and invoke the callback 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.

const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
const items = ['Pencil', 'Notebook', 'Yo-yo', 'Gum'];

/*

Expand Down Expand Up @@ -39,24 +39,77 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];
*/


function getLength(arr, cb) {
function getLength(array, callback) {
// getLength passes the length of the array into the callback.
}
return callback(array.length);
};
// I'm creating the variable to test the callback of the total items in the array
let test1 = getLength(items, totalItems => `There are ${totalItems} items in the array!`);
console.log(test1);

function shortArray(number) {
return `This array of ${number} items is the shortest array I have..`;
};

let test2 = getLength(items, shortArray);
console.log(test2);

function last(arr, cb) {
// ------------------------------------------------------------------------------------------

function last(array, callback) {
// last passes the last item of the array into the callback.
}
return callback(array[3]);
};

function sumNums(x, y, cb) {
test1 = last(items, item => `Most schools have a standard rule about NO ${item} on campus, but I still always chewed it..`);
console.log(test1);

function schoolSupplies(supplies) {
return `${supplies} has always been my go-to study helper for keeping my thoughts on track and staying busy..`
};

test2 = last(items, schoolSupplies);
console.log(test2);

// ------------------------------------------------------------------------------------------
let x = 12;
let y = 12;
function sumNums(x, y, callback) {
// sumNums adds two numbers (x, y) and passes the result to the callback.
}
return callback(x + y);
};

test1 = sumNums(x, y, sumTotal => `So the sum total of ${x} + ${y} = ${sumTotal}.`);
console.log(test1);

function add(total) {
return `The total sum of ${x} and ${y} is ${total}..`
};

test2 = sumNums(x, y, add);
console.log(test2);
// ------------------------------------------------------------------------------------------

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

test1 = multiplyNums(x, y, multiplied => `If you multiply ${x} and ${y}, you'll get ${multiplied}..`);
console.log(test1);

function multiply(total) {
return `We all know that ${x} X ${y} equals ${total}..`
};

test2 = multiplyNums(x, y, multiply);
console.log(test2);

// ------------------------------------------------------------------------------------------

function contains(item, list, cb) {
// contains checks if an item is present inside of the given array/list.

// Pass true to the callback if it is, otherwise pass false.
}

Expand Down
7 changes: 7 additions & 0 deletions assignments/closure.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
// that manipulates variables defined in the outer scope.
// The outer scope can be a parent function, or the top level of the script.

let webPt11_jeff = ['Adrian', 'Brian', 'Shaurice', 'Bret', 'Leisha', 'Samuel', 'Dak', 'Samet']
function allStudents () {
return webPt11_jeff.sort();
};

console.log("Jeffrey's group of students include all the cool kids named " + allStudents() + " and we love Javascript!!");


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

Expand Down