From 3288e1534e6d3ba8ab14d56c27b3475c6f4c25e0 Mon Sep 17 00:00:00 2001 From: gormangit Date: Thu, 9 Nov 2017 19:39:18 -0600 Subject: [PATCH 1/2] higherOreder --- 06week/higherOrder.js | 49 +++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/06week/higherOrder.js b/06week/higherOrder.js index 73926e3dc..dc598c759 100644 --- a/06week/higherOrder.js +++ b/06week/higherOrder.js @@ -2,18 +2,45 @@ const assert = require('assert'); -function forEach(arr, callback) { - // Your code here -} - -function map(arr, callback) { - // Your code here -} - -function filter(arr, callback) { - // Your code here -} +// function forEach(arr, callback){ +const forEach = (inputArray, inputFunction) => { + const anotherArr = []; + for (let i = 0; i < inputArray.length; i++){ + anotherArr.push(inputFunction(inputArray[i])); + console.log(inputArray.length) + } + // return anotherArr; +}; +const fullArray = [1, 2, 3]; +const inputFunction = i => fullArray.length; +forEach(fullArray, inputFunction); +// function map(arr, callback) { +// +// } +const map = (arg1, arg2) => { + let nums = []; + arg1.forEach(index => nums.push(arg2(index))); + return nums; +}; +const add2 = i => i+2; +const array = [1, 2, 3, 4]; +map(array, add2); +// function filter(arr, callback) { +// // Your code here +// } +const filter = (inpt , inFun) => { + let arr1 = []; + for (let i = 0; i < inpt.length; i++){ + if(inFun(inpt[i])) { + arr1.push(inpt[i]); + } + }return arr1; +}; +const filtArray = [1,2,3,4]; +filter(filtArray, (x) => { + return x > 2; +}); function some(arr, callback) { // Your code here } From 11a9f09dbcf2a58a03de979ac600c94f32657335 Mon Sep 17 00:00:00 2001 From: gormangit Date: Sun, 26 Nov 2017 10:18:07 -0600 Subject: [PATCH 2/2] changes --- 06week/higherOrder.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/06week/higherOrder.js b/06week/higherOrder.js index dc598c759..d06992418 100644 --- a/06week/higherOrder.js +++ b/06week/higherOrder.js @@ -4,17 +4,29 @@ const assert = require('assert'); // function forEach(arr, callback){ +// ** method +// var arr1 = [1, 2, 3,] +// arr1.forEach(function(entry){ +// console.log(entry) +// }) + +// this is forEach function that iterates over each item in array with defined function. for each item +// in array dot length perform inputfunction const forEach = (inputArray, inputFunction) => { - const anotherArr = []; - for (let i = 0; i < inputArray.length; i++){ - anotherArr.push(inputFunction(inputArray[i])); - console.log(inputArray.length) - } - // return anotherArr; + for (let i = 0; i < inputArray.length; i++){ + inputFunction(inputArray[i]); + + } }; +//this is the array const fullArray = [1, 2, 3]; -const inputFunction = i => fullArray.length; -forEach(fullArray, inputFunction); +// this is a function that uses fullArray as the argument and then console logs it as the function. +function funky(fullArray) { + console.log(fullArray); +} +//calling fullArray and funky to run the forEach function logs the exact same thing as a forEach method +forEach(fullArray, funky); + // function map(arr, callback) { // // }