From 5d5dbeac75b9e651894a31a2b640b93e4ae61e94 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 10:01:31 +0100 Subject: [PATCH 01/24] function mulyiply done --- src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 9a44281..fa53814 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(){ From db0b5b76bb048542d2d64372f15d5af293b38476 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 10:07:59 +0100 Subject: [PATCH 02/24] function avg done --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index fa53814..9becc9e 100644 --- a/src/index.js +++ b/src/index.js @@ -9,15 +9,17 @@ 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 + return (a+b+c+d+e)/5; } function remainder(){ // this function is passed 2 arguments // return the remainder of first // argument when divided by the second + } function exponential(){ From a7883a240d5bad5b39bd8ca4a9b9f4339ad9c103 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 10:09:07 +0100 Subject: [PATCH 03/24] function remainder done --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 9becc9e..22eca33 100644 --- a/src/index.js +++ b/src/index.js @@ -15,11 +15,11 @@ function average(a,b,c,d,e){ return (a+b+c+d+e)/5; } -function remainder(){ +function remainder(first, second){ // this function is passed 2 arguments // return the remainder of first // argument when divided by the second - + return first%second; } function exponential(){ From d66dff5d5d876c768d48460d8a7d665acdcc671c Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 10:10:57 +0100 Subject: [PATCH 04/24] function exponential done --- src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 22eca33..a607896 100644 --- a/src/index.js +++ b/src/index.js @@ -22,10 +22,11 @@ function remainder(first, second){ return first%second; } -function exponential(){ +function exponential(first, second){ // 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 first ** second; } function laxEquality(){ From 631d87392e47f3e0ebf465be776f146012234823 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 10:13:04 +0100 Subject: [PATCH 05/24] laxEquality done --- src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index a607896..718dff8 100644 --- a/src/index.js +++ b/src/index.js @@ -29,9 +29,10 @@ function exponential(first, second){ return first ** second; } -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(){ From 8ed8faeae8a5e5235405a22553f9329afc89f2d3 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 10:15:30 +0100 Subject: [PATCH 06/24] function strictequal is done --- src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 718dff8..4b37889 100644 --- a/src/index.js +++ b/src/index.js @@ -35,9 +35,10 @@ function laxEquality(a,b){ 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 + return (a === b) && (b === c); } function smaller(){ From 36673a1e8114daa93123e280da6a45cd2d6d0159 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 10:22:20 +0100 Subject: [PATCH 07/24] function smaller is done --- src/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 4b37889..889b9b9 100644 --- a/src/index.js +++ b/src/index.js @@ -41,10 +41,16 @@ function strictEqual(a,b,c){ return (a === b) && (b === c); } -function smaller(){ +function smaller(first, second){ // this function is passed 2 arguments // return true if second argument is // greater than or equal to first, otherwise return string 'smaller' + if (second >= first){ + return true; + }else{ + return "smaller"; + } + } function isDivisibleBy(divider1, divider2, number){ From f23e6b80b3613191f9f10eba8d1036ac393caa49 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 10:31:28 +0100 Subject: [PATCH 08/24] function isDivisibleBy done --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 889b9b9..629897b 100644 --- a/src/index.js +++ b/src/index.js @@ -56,6 +56,7 @@ function smaller(first, second){ 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(){ From 008e7c73a8f6805580ccc0f6b1ea013aee9e2bbc Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 10:33:54 +0100 Subject: [PATCH 09/24] function evens is done --- src/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 629897b..11286dc 100644 --- a/src/index.js +++ b/src/index.js @@ -59,10 +59,11 @@ function isDivisibleBy(divider1, divider2, number){ 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 ){ From d6db896bbfb82f3e2c73612ddd1ad62598eedc92 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 10:44:23 +0100 Subject: [PATCH 10/24] function remove middle done --- src/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/index.js b/src/index.js index 11286dc..611f490 100644 --- a/src/index.js +++ b/src/index.js @@ -71,6 +71,9 @@ 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 middle=(words.length-1)/2 + let newArray= words.splice(middle,1); + return newArray; } function get2ndAnd3rd( myArray ){ From b9a85c765b55c90477072ff5d7ded5129869d628 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 10:50:00 +0100 Subject: [PATCH 11/24] function get2ndand3rd is done --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 611f490..e9edbf0 100644 --- a/src/index.js +++ b/src/index.js @@ -81,6 +81,7 @@ function get2ndAnd3rd( myArray ){ // return an array containing the 2nd and 3rd items from myArray // myArray should remain unchanged // hint: slice + return myArray.slice(1,3); } function mapper( myArray ){ From 561405a63a690877fa25d0f60eb635c8209142d6 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 10:52:32 +0100 Subject: [PATCH 12/24] function mapper is done --- src/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/index.js b/src/index.js index e9edbf0..5205e8c 100644 --- a/src/index.js +++ b/src/index.js @@ -88,6 +88,10 @@ 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 + return myArray.map(function(item){ + return item + 1; + }); + } function wordLengths( words ){ From 6d872a49e8d6136bdefbb3bca35f814a3db29c7b Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 10:55:19 +0100 Subject: [PATCH 13/24] function wordLengths is done --- src/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/index.js b/src/index.js index 5205e8c..d79e005 100644 --- a/src/index.js +++ b/src/index.js @@ -102,6 +102,9 @@ function wordLengths( words ){ // [ 'jupiter', 'mars', 'saturn' ] // output: // [ 7, 4, 6] + return words.map(function(item){ + return item.length; + }); } function cities( capitals, formatter ){ From cdaea0d4c343d22da1c12473924fb213de8861eb Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 11:08:49 +0100 Subject: [PATCH 14/24] function cities is done --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index d79e005..802d18d 100644 --- a/src/index.js +++ b/src/index.js @@ -119,6 +119,7 @@ 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 + return capitals.map(formatter); } function largerThanTen( numbers ){ From cb5ee3612cd164027145c898b527005bf35422f3 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 11:11:00 +0100 Subject: [PATCH 15/24] function laregrThanTen is done --- src/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/index.js b/src/index.js index 802d18d..98c26a0 100644 --- a/src/index.js +++ b/src/index.js @@ -126,6 +126,9 @@ 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 + return number.filter(function(item){ + return item > 10; + }); } function even( numbers ){ From b51b00617f3e90149b132ca399ef5b18ea4f1faf Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 11:15:10 +0100 Subject: [PATCH 16/24] function findTheNeddle is done --- src/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/index.js b/src/index.js index 98c26a0..2206d40 100644 --- a/src/index.js +++ b/src/index.js @@ -134,11 +134,17 @@ 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 + return numbers.filter(function(item){ + return item % 2 === 0; + }); } function findTheNeedle( words ){ // words is an array of words // return the index of the word 'needle' + return words.find(function(item){ + return item === "needle"; + }); } function findLargest( numbers ){ From 1e827a0d81f8079c5f6b95871ea8578f1a8ac886 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 11:32:19 +0100 Subject: [PATCH 17/24] function assAllNumbers is done --- src/index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/index.js b/src/index.js index 2206d40..b92653a 100644 --- a/src/index.js +++ b/src/index.js @@ -150,11 +150,29 @@ function findTheNeedle( words ){ function findLargest( numbers ){ // numbers is an array of numbers // return the largest number from that array +/* let max = numbers[0]; + for(let i = 0; i < numbers.length; i++){ + if(numbers[i] > max){ + max = numbers[i]; + } + + } + return max; */ + + return numbers.reduce(function(acc,item){ + if (item>acc){ + return item; + } + return acc; + },numbers[0]); } function addAllnumbers( numbers ) { // numbers is an array of numbers // return the sum of all the numbers in the array + return numbers.reduce(function(acc,item){ + return acc+item; + },0) } function averages( things ) { From 37e9c754d9cdd5d2cdb7e19646075fd15821b242 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 11:43:21 +0100 Subject: [PATCH 18/24] function average is done --- src/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/index.js b/src/index.js index b92653a..5fa7468 100644 --- a/src/index.js +++ b/src/index.js @@ -179,6 +179,14 @@ function averages( things ) { // things is an array of numbers and strings // return the average of all the numbers // be sure to exclude the strings + let counter=0; + return (things.reduce(function(acc,item){ + if (typeof item === "number"){ + counter++; + return acc+item; + } + return acc; + },0) ) /counter; } function sortingStrings(strings){ From 8d7fc95633622227c31b663b541edfe4099b0642 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 11:44:39 +0100 Subject: [PATCH 19/24] function sortingStrings is done --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 5fa7468..bd53870 100644 --- a/src/index.js +++ b/src/index.js @@ -192,6 +192,7 @@ function averages( things ) { function sortingStrings(strings){ // strings is an array of strings // sort them in alphabetical order and return the sorted array + return strings.sort(); } function sortingNumbers(numbers){ From 715b6fa68483a9822d74cb2e529bce11cbf288a8 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 12:04:01 +0100 Subject: [PATCH 20/24] funtion sortingNumbers --- src/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/index.js b/src/index.js index bd53870..42e5b86 100644 --- a/src/index.js +++ b/src/index.js @@ -198,11 +198,15 @@ function sortingStrings(strings){ function sortingNumbers(numbers){ // things is an array of sortingStrings // sort them in ascending order and return the sorted array + return numbers.sort(function(a,b){ + return a-b; + }); } function sortingNumbersDescending(numbers){ // things is an array of sortingStrings // sort them in descending order and return the sorted array + } function sortingCars(cars){ From e7de97edb2f6447bae1ec068d9402db5e96a5407 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 12:05:05 +0100 Subject: [PATCH 21/24] sortingNumbersDescending us done --- src/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/index.js b/src/index.js index 42e5b86..68f9860 100644 --- a/src/index.js +++ b/src/index.js @@ -206,6 +206,9 @@ function sortingNumbers(numbers){ function sortingNumbersDescending(numbers){ // things is an array of sortingStrings // sort them in descending order and return the sorted array + return numbers.sort(function(a,b){ + return b-a; + }); } From 45ddb16479c5535bdd6f070fce69da88921bf972 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 12:17:54 +0100 Subject: [PATCH 22/24] function sortingCars is done --- src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 68f9860..1f7c4dd 100644 --- a/src/index.js +++ b/src/index.js @@ -222,7 +222,11 @@ function sortingCars(cars){ // // cars is an array of car objects. Sort them ascending by year and return // the sorted array. -} + return cars.sort(function(a,b){ + return a.year - b.year; + }); + + } function deleteColour( car ){ // car is an object with properties make, model and color. For example From 566df29706523094f26898352a9f6ca361d68900 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 1 Jun 2018 14:29:31 +0100 Subject: [PATCH 23/24] funtion deleteColur is done --- src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 1f7c4dd..4af7b6c 100644 --- a/src/index.js +++ b/src/index.js @@ -237,7 +237,11 @@ function deleteColour( car ){ // } // delete the property colour and return car without this property -}; + for(let i=0;i Date: Fri, 1 Jun 2018 16:49:29 +0100 Subject: [PATCH 24/24] function secondLargest is done and we are done --- src/index.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/index.js b/src/index.js index 4af7b6c..2d5d03a 100644 --- a/src/index.js +++ b/src/index.js @@ -259,12 +259,33 @@ function paintShop( cars, colour ){ // the original array passed in should not change // hint: look up 'Cloning objects in JavaScript' +let newItem; + + +return cars.map(function(item){ +if(item.make === "Ford" ){ + newItem=Object.assign({},item); + newItem.color=colour; + return newItem; + } +}); + +}) } function secondLargest( numbers ){ // numbers is an array of numbers // return the index of the second // largest number in the array + let counter=-1; + let copied = numbers.slice().sort(function(a,b){ + return b - a; + }); + return numbers.find(function(item){ + counter++; + return copied[1] === item; + }); + return counter; } function addSales( city, sales ){