From d2889648aa22c2c99ad3afb92b610e2f70bd124d Mon Sep 17 00:00:00 2001 From: Jordon R Date: Fri, 6 Oct 2017 20:05:46 -0500 Subject: [PATCH] Committing passing find filter and map --- src/services/array-functions.js | 37 ++++++++++++++++++++++++------- src/tests/array-functions.test.js | 18 ++++++++++++--- src/tests/calculations.test.js | 21 +++++++++++++++++- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/services/array-functions.js b/src/services/array-functions.js index ff781d2..7bacb91 100644 --- a/src/services/array-functions.js +++ b/src/services/array-functions.js @@ -1,29 +1,50 @@ //in the function map, create a new array and store in a variable -//loop theArray and call the fnc for each thing in the array, +//loop theArray and call the fnc for each thing in the array, // passing in the item from the current loop into the call to fnc //add the returned value from fnc to the new array //return the new array export function map(theArray, fnc){ - + const newArr = []; + for (let i=0; i { //filter should return an array with names of length 3 //["Jon","Bob","Ted","Axe"] +describe("filter", () => { + it("should return an array with names of length 3", () => { + expect(filter(names,findThree)).toEqual([ + "Jon","Bob","Ted","Axe" + ]); + }); +}); //find should find one name of "Barney" - +describe("find", () => { + it("should find one name of Barney", () => { + expect(find(names,findBarney)).toEqual( + "Barney" + ); + }); +}); //findLast should find the last name of "Axe" //reverse should return an array with the elements in the opposite order //["Axe","Saul","Robin","Lilly","Barney","Ted","Bob","Jon"] + //tail should return all elements in an array except the first one //[Bob","Ted","Barney","Lilly","Robin","Saul","Axe"]; - - diff --git a/src/tests/calculations.test.js b/src/tests/calculations.test.js index 409e055..ab51c2d 100644 --- a/src/tests/calculations.test.js +++ b/src/tests/calculations.test.js @@ -1,7 +1,26 @@ -import {add, subtract, multiply,divide} from "../services/calculations"; +import {add, subtract, multiple,divide} from "../services/calculations"; describe("add", () => { it("should add 1 and 2 and return 3", () => { expect(add(1, 2)).toBe(3); }); }); + + +describe("subtract", () => { + it("should subtract 2 from 3 and return 1", () => { + expect(subtract(3,2)).toBe(1); + }); +}); + +describe("multiply", () => { + it("should multiply 2 and 2 and return 4", () => { + expect(multiple(2,2)).toBe(4); + }); +}); + +describe("divide", () => { + it("should divide 2 into 4 and return 2", () => { + expect(divide(4,2)).toBe(2); + }); +});