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
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
69 changes: 56 additions & 13 deletions src/services/array-functions.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,87 @@

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


//return the last item in theArray
export function findLast(theArray){

var last = theArray[theArray.length-1]
return last;
}

//return the first element of the array
export function head(theArray){

var first = theArray[0]
return first;
}

//create a new array
//loop theArray in reverse order
//add the item from each loop to the new array
//return the new array
export function reverse(theArray){

var newArray = [];
for (var i = theArray.length-1; i >= 0; i--){
var item = theArray[i];
newArray.push(item);
}
return newArray;
}

//create a new array
//loop theArray
//add the item from each loop to the new array except the first item
//return the new array
export function tail(theArray){

var newArray[];
for(var i = 1; i < theArray.length; i++){
var item = theArray[i];
newArray.push(item);
}
return newArray;
}

//implement the most basic sorting algorithm there is
Expand All @@ -64,5 +95,17 @@ export function tail(theArray){
//after each for loop check the variable, if true, continue the while loop
//if false return theArray
export function sort(theArray){

}
do {
var swap = false;
for(var i = 0; i < theArray.length; i++) {
var currentItem = theArray[i];
var nextItem = theArray[i+1];
if (currentItem > secondItem) {
theArray[i] = nextItem;
theArray[i+1] = currentItem;
var swap = true;
}
}
while (swap);
}
}
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){
}

}
33 changes: 27 additions & 6 deletions src/tests/array-functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function findThree(name){
function findBarney(name){
return name === "Barney";
}

//head should find the first element in the array "Jon"
describe("head", () => {
it("should return the first element of an array 'Jon'", () => {
Expand Down Expand Up @@ -42,16 +43,36 @@ 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"
describe("findLast", () => {
it("should find the last name in the array", () => {
expect(findLast(names)).toEqual("Axe");
});
});//findLast should find the last name of "Axe"

//reverse should return an array with the elements in the opposite order
describe("reverse", () => {
it("should return array with elements in opposing order", () => {
expect(reverse(names)).toEqual(["Axe","Saul","Robin","Lilly","Barney","Ted","Bob","Jon"]);
});
});//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"];


describe("tail", () => {
it("should return all elements except in array except first item", () => {
expect(tail(names)).toEqual(["Bob","Ted","Barney","Lilly","Robin","Saul","Axe"]);
});
});//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