From 7769bba4c9d4ed41e883ec75a169bd7b9fbd14b8 Mon Sep 17 00:00:00 2001 From: HTLuff Date: Fri, 1 Jun 2018 10:03:32 +0100 Subject: [PATCH 1/8] first commit --- src/index.js | 3 ++- test/index.test.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 9a44281..098fd0d 100644 --- a/src/index.js +++ b/src/index.js @@ -3,9 +3,10 @@ function add(a, b){ return a + b; } -function multiply(){ +function multiply(a,b,c,d){ // this function is passed 4 parameters // multiply them and return the result + return a * b * c * d; } function average(){ diff --git a/test/index.test.js b/test/index.test.js index 7334fb2..824af04 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -41,7 +41,7 @@ test('Add', () => { expect( result ).toEqual( 5 ); }); -test('Multiply', () => { +test.only('Multiply', () => { const result = multiply( 4, 5, 3, 7 ); expect( result ).toEqual( 420 ); From 1f13ad5130515747b0041d98ca38fbd95c195cc1 Mon Sep 17 00:00:00 2001 From: HTLuff Date: Fri, 1 Jun 2018 10:29:47 +0100 Subject: [PATCH 2/8] Second,third and Fourth questions --- src/index.js | 10 +++++++--- test/index.test.js | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 098fd0d..7877012 100644 --- a/src/index.js +++ b/src/index.js @@ -9,21 +9,25 @@ function multiply(a,b,c,d){ return a * b * c * d; } -function average(){ +function average(a,b,c,d,e){ // this function is passed 5 heights in meters // calculate their average and return it + let total = 0; + return (a+b+c+d+e) / 5; } -function remainder(){ +function remainder(a,b){ // this function is passed 2 arguments // return the remainder of first // argument when divided by the second + return a % b; } -function exponential(){ +function exponential(a,b){ // this function is passed 2 arguments // return first argument to the power of second argument // hint: you may need to look up the exponention operator + return a ** b; } function laxEquality(){ diff --git a/test/index.test.js b/test/index.test.js index 824af04..4d575e1 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -41,7 +41,7 @@ test('Add', () => { expect( result ).toEqual( 5 ); }); -test.only('Multiply', () => { +test('Multiply', () => { const result = multiply( 4, 5, 3, 7 ); expect( result ).toEqual( 420 ); @@ -59,7 +59,7 @@ test('Remainder', () => { expect( result ).toEqual( 2 ); }); -test('Exponential', () => { +test.only('Exponential', () => { const result = exponential( 7, 4 ); expect( result ).toEqual( 2401 ); From d162523aa6429c7979c37878c0dfad2d55254767 Mon Sep 17 00:00:00 2001 From: HTLuff Date: Fri, 1 Jun 2018 10:30:19 +0100 Subject: [PATCH 3/8] Second,third and Fourth questions --- test/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.test.js b/test/index.test.js index 4d575e1..7334fb2 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -59,7 +59,7 @@ test('Remainder', () => { expect( result ).toEqual( 2 ); }); -test.only('Exponential', () => { +test('Exponential', () => { const result = exponential( 7, 4 ); expect( result ).toEqual( 2401 ); From c3bad0c5bb650af9ae2896ca23ef9c432974bbd6 Mon Sep 17 00:00:00 2001 From: HTLuff Date: Fri, 1 Jun 2018 10:45:07 +0100 Subject: [PATCH 4/8] 5th, 6th, 7th, 8th --- src/index.js | 18 ++++++++++++++---- test/index.test.js | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 7877012..1a1fcff 100644 --- a/src/index.js +++ b/src/index.js @@ -27,23 +27,33 @@ function exponential(a,b){ // this function is passed 2 arguments // return first argument to the power of second argument // hint: you may need to look up the exponention operator - return a ** b; + return a ** b; } -function laxEquality(){ +function laxEquality(a,b){ // this function is passed 2 arguments // return true if they are equal but not strictly equal + return a !== b; } -function strictEqual(){ +function strictEqual(a,b,c){ // function is passed 3 arguments // return true if they are all strictly equal and false otherwise + if(a === b && b === c){ + return true; + } + return false; } -function smaller(){ +function smaller(a,b){ // this function is passed 2 arguments // return true if second argument is // greater than or equal to first, otherwise return string 'smaller' + if(b >= a){ + return true + } else { + return "smaller"; + } } function isDivisibleBy(divider1, divider2, number){ diff --git a/test/index.test.js b/test/index.test.js index 7334fb2..4a629e2 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -87,7 +87,7 @@ test('Strict equal ', () => { expect( result4 ).toEqual( false ); }); -test('Smaller', () => { +test.only('Smaller', () => { const result1 = smaller( 7, 7 ); expect( result1 ).toEqual( true ); From f1749ec7c0b05186ffa59d46775478e963f7efc5 Mon Sep 17 00:00:00 2001 From: HTLuff Date: Fri, 1 Jun 2018 11:47:17 +0100 Subject: [PATCH 5/8] 9th,10th --- src/index.js | 13 ++++++++++++- test/index.test.js | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 1a1fcff..98e05e7 100644 --- a/src/index.js +++ b/src/index.js @@ -59,12 +59,14 @@ function smaller(a,b){ function isDivisibleBy(divider1, divider2, number){ // if number is divisible by divider1 or divider2 return true or false otherwise // do not use if/else or ternary + return number % divider1 === 0 || number % divider2 === 0 } -function evens(){ +function evens(a,b,c,d){ // this function is passed 4 numbers // return true if all numbers are even or false otherwise // do not use if/else or ternary + return a % 2 === 0 && b % 2 === 0 && c % 2 === 0 && d % 2 === 0 ; } function removeMiddle( words ){ @@ -72,6 +74,15 @@ function removeMiddle( words ){ // return a new array containing only the middle word // the words array should no longer contain the middle word // hint: splice + let middleWordIndex = Math.floor((words.length - 1) / 2) + + let middleWord = [words[middleWordIndex]]; + let newArr = words.splice(middleWordIndex, 1); + + + return middleWord; + + } function get2ndAnd3rd( myArray ){ diff --git a/test/index.test.js b/test/index.test.js index 4a629e2..a3d8462 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -87,7 +87,7 @@ test('Strict equal ', () => { expect( result4 ).toEqual( false ); }); -test.only('Smaller', () => { +test('Smaller', () => { const result1 = smaller( 7, 7 ); expect( result1 ).toEqual( true ); @@ -127,7 +127,7 @@ test('Evens', () => { expect( result4 ).toEqual( false ); }); -test('Remove middle', () => { +test.only('Remove middle', () => { const words = [ 'mouse', 'giraffe', 'queen', 'window', 'bottle']; const expectedWords = [ 'mouse', 'giraffe', 'window', 'bottle']; From d2b0de859b98b9b91a43737ded11cf83faaa13d8 Mon Sep 17 00:00:00 2001 From: HTLuff Date: Fri, 1 Jun 2018 12:01:48 +0100 Subject: [PATCH 6/8] another 3 questions done --- src/index.js | 12 ++++++++++++ test/index.test.js | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 98e05e7..450207f 100644 --- a/src/index.js +++ b/src/index.js @@ -90,12 +90,19 @@ function get2ndAnd3rd( myArray ){ // return an array containing the 2nd and 3rd items from myArray // myArray should remain unchanged // hint: slice + let twoAndThree = myArray.slice(1,3); + return twoAndThree; } function mapper( myArray ){ // myArray is an array of numbers // return a new array which has all items in myArray incremented by one // myArray should remain unchanged + let newArr = myArray.map(function(num){ + num += 1; + return num; + }); + return newArr; } function wordLengths( words ){ @@ -106,6 +113,11 @@ function wordLengths( words ){ // [ 'jupiter', 'mars', 'saturn' ] // output: // [ 7, 4, 6] + let newArr = words.map(function(num){ + num = num.length; + return num; + }); + return newArr; } function cities( capitals, formatter ){ diff --git a/test/index.test.js b/test/index.test.js index a3d8462..7334fb2 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -127,7 +127,7 @@ test('Evens', () => { expect( result4 ).toEqual( false ); }); -test.only('Remove middle', () => { +test('Remove middle', () => { const words = [ 'mouse', 'giraffe', 'queen', 'window', 'bottle']; const expectedWords = [ 'mouse', 'giraffe', 'window', 'bottle']; From 6dc5488c22ae3e8db71e243933ce6912b95085d2 Mon Sep 17 00:00:00 2001 From: HTLuff Date: Fri, 1 Jun 2018 12:29:24 +0100 Subject: [PATCH 7/8] another 2 questions done --- src/index.js | 7 +++++++ test/index.test.js | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 450207f..b71fb26 100644 --- a/src/index.js +++ b/src/index.js @@ -132,12 +132,19 @@ function cities( capitals, formatter ){ // 'Paris is the capital of France'. // Apply formatter to each object in capitals array and // return an array of resulting sentences + const formatted = capitals.map(formatter) + //return formatter(this.city,this.country); + return formatted; } function largerThanTen( numbers ){ // numbers is an array of numbers // return a new array that contains only numbers // from the input array which are greater than 10 + let arr = numbers.filter(function(num){ + return num > 10; + }); + return arr; } function even( numbers ){ diff --git a/test/index.test.js b/test/index.test.js index 7334fb2..e719e66 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -193,7 +193,7 @@ test('Cities', () => { expect(result).toEqual(expected); }); -test('Get numbers greater than 10', () => { +test.only('Get numbers greater than 10', () => { const numbers = [ 4, 10, 32, 9, 21]; const expected = [ 32, 21 ]; From 36cbee38f15953500ca6e78738ee3a9b0c242d75 Mon Sep 17 00:00:00 2001 From: HTLuff Date: Fri, 1 Jun 2018 14:35:27 +0100 Subject: [PATCH 8/8] another few questions done - up to & including add all numbers --- src/index.js | 17 +++++++++++++++++ test/index.test.js | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index b71fb26..a31c932 100644 --- a/src/index.js +++ b/src/index.js @@ -150,21 +150,38 @@ function largerThanTen( numbers ){ function even( numbers ){ // numbers is an array of numbers // return a new array that contains only even numbers from the input array + let newArr = []; + let newNum = numbers.map(function(num){ + if (num % 2 === 0){ + newArr.push(num); + } + return num; + }); + return newArr; } function findTheNeedle( words ){ // words is an array of words // return the index of the word 'needle' + var needleFound = words.findIndex(function(item){ + return item === "needle"; + }); + return needleFound; } function findLargest( numbers ){ // numbers is an array of numbers // return the largest number from that array + return Math.max(...numbers); } function addAllnumbers( numbers ) { // numbers is an array of numbers // return the sum of all the numbers in the array + let numSum = numbers.reduce(function(acc, num){ + return acc + num; + }, 0); + return numSum; } function averages( things ) { diff --git a/test/index.test.js b/test/index.test.js index e719e66..7334fb2 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -193,7 +193,7 @@ test('Cities', () => { expect(result).toEqual(expected); }); -test.only('Get numbers greater than 10', () => { +test('Get numbers greater than 10', () => { const numbers = [ 4, 10, 32, 9, 21]; const expected = [ 32, 21 ];