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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# JavaScript - II
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.
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.

## Assignment Description

Expand Down
5 changes: 5 additions & 0 deletions assignments/callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum'];

function firstItem(arr, cb) {
// firstItem passes the first item of the given array to the callback function.
return callback(arr);
}

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

function last(arr, cb) {
Expand All @@ -14,15 +16,18 @@ function last(arr, cb) {

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

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) {
// 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 */
Expand Down
20 changes: 15 additions & 5 deletions assignments/function-conversion.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
// Take the commented ES5 syntax and convert it to ES6 arrow Syntax

// let myFunction = function () {};
let myFunction= () => {return "no params"};
myFunction();

// let anotherFunction = function (param) {
// return param;
// };
let anotherFunction= (param) => {return param};
anotherFunction(1);

// let add = function (param1, param2) {
// return param1 + param2;
// };
// add(1,2);
let add= (param1,param2) => {return param1+param2};
add(1,2);

let subtract = function (param1, param2) {
return param1 - param2;
};
subtract(1,2); //?
// let subtract = function (param1, param2) {
// return param1 - param2;
// };
// subtract(1,2);
let subtract= (param1,param2) => {return param1-param2};
subtract(1,2);

exampleArray = [1,2,3,4];
// const triple = exampleArray.map(function (num) {
// return num * 3;
// });
// console.log(triple);
// console.log(triple);
const triple= exampleArray.map(function, (num)) => {return num*3};
console.log(triple);