Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9,319 changes: 9,319 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"whatwg-fetch": "^2.0.3"
},
"devDependencies": {
"jest": "^21.2.1",
"react-scripts": "0.9.5"
},
"scripts": {
Expand Down
36 changes: 28 additions & 8 deletions src/services/array-functions.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@

//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){

var newArray = [];
for(var i=0; i < theArray.length; i++){
var currentItem = thearray[i];
var returnedItem = fnc(currentItem);
newArray[i]= (returnedItem);
}
return newArray;
}

//create a new array
//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
//fnc will return true or false, if true add the item to the new array else do not
//return the new array
export function filter(theArray, fnc){

var newArray = [];
for(var i = 0; i < theArray.length; i++){
var currentItem = theArray[i];
var returnedItem = fnc(currentItem);
if (returnedItem = true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double check your use of javascript code
how do you compare something to true

newArray.push(returnedItem);
}
return newArray;
}


//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
//fnc will return true or false, if true return the item
//fnc will return true or false, if true return the item
//return null
export function find(theArray, fnc){

for(var i = 0; i < theArray.length; i++){
var currentItem = theArray[i];
var returnedItem = fnc(currentItem);
if (returnedItem = true) {
return returnedItem;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the most part, you don't ever want to have an else statement in a loop

return null
}
}


Expand Down Expand Up @@ -65,4 +85,4 @@ export function tail(theArray){
//if false return theArray
export function sort(theArray){

}
}
2 changes: 1 addition & 1 deletion src/services/calculations.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export function multiple(num1, num2){
}
export function divide(num1, num2){
return num1 / num2;
}
}
12 changes: 6 additions & 6 deletions src/services/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
create a new function called theAfter in the after function
when theAfter is called increment the counter
if counter === times, call theFunc()
return the theAfter
return the theAfter
*/
export function after(times, theFunc){

Expand All @@ -16,22 +16,22 @@ export function after(times, theFunc){
create a new function called theBefore in the before function
when theBefore is called increment the counter
if counter <= times, call theFunc()
return the theBefore
return the theBefore
*/
export function before(times, theFunc){

}

/*
Creates a function that is restricted to invoking theFunc once.
Creates a function that is restricted to invoking theFunc once.
Repeat calls to the function return the value of the first invocation.
create a variable called firstValue and set it to null
create a new function called theOnce
in theOnce check if firstValue is null,
in theOnce check if firstValue is null,
if so call theFunc and assign the returned value into firstValue
return firstValue
return theOnce
*/
export function once(theFunc){
}

}
14 changes: 10 additions & 4 deletions src/tests/array-functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,22 @@ describe("sort", () => {
});
});

//filter should return an array with names of length 3
describe("filter", () => {
it("should return array with names of length 3", () => {
expect(filter(names), findThree).toEqual(["Jon", "Bob", "Ted", "Axe"]);
});
});//filter should return an array with names of length 3
//["Jon","Bob","Ted","Axe"]

//find should find one name of "Barney"
describe("find", () => {
it("should find the single name of Barney", () => {
expect(find(names), findBarney).toEqual("Barney");
});
});//find should find one name of "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"];


21 changes: 20 additions & 1 deletion src/tests/calculations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@ import {add, subtract, multiply,divide} from "../services/calculations";

describe("add", () => {
it("should add 1 and 2 and return 3", () => {
expect(add(1, 2)).toBe(3);
var result = add(1, 2)
expect(result).toBe(3);
});
});

describe("subtract", () => {
it("should subtract 4 from 5 and return 1", () => {
var result = subtract(5, 4)
expect(result).toBe(1);
});
});

describe("multiply", () => {
it("should multiply 4 by 5 and return 20", () => {
var result = multiply(5, 4)
expect(result).toBe(20);
});
});

// * subtracts 4 from 5 to equal 1
// * multiply 4 by 5 to equal 20
// * device 100 by 4 to equal 25
2 changes: 1 addition & 1 deletion src/tests/counter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ describe("CounterButtonContainer", () => {
var div = wrapper.find("div").at(2);
expect(div.text()).toBe("Counter: -4");
});
});
});
Loading