diff --git a/README.md b/README.md index 854374d80..b92efd5f9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/assignments/callbacks.js b/assignments/callbacks.js index a551f853b..2ab81864c 100644 --- a/assignments/callbacks.js +++ b/assignments/callbacks.js @@ -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) { @@ -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 */ diff --git a/assignments/function-conversion.js b/assignments/function-conversion.js index 5e6a658a4..d833a1966 100644 --- a/assignments/function-conversion.js +++ b/assignments/function-conversion.js @@ -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); \ No newline at end of file +// console.log(triple); +const triple= exampleArray.map(function, (num)) => {return num*3}; +console.log(triple); \ No newline at end of file