From 42bb040c2c4d527452632bf4c1748cce70f86f39 Mon Sep 17 00:00:00 2001 From: khaled-Mohamed1 Date: Wed, 3 Feb 2021 22:50:35 +0300 Subject: [PATCH 1/5] my first commit solve toy problem --- firstToyProblem.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/firstToyProblem.js b/firstToyProblem.js index b0873e7..d82de81 100644 --- a/firstToyProblem.js +++ b/firstToyProblem.js @@ -5,5 +5,13 @@ */ function minimum(array) { - return; + var smallest = array[0] + for(i of array){ + if( i < smallest){ + smallest = i + } + } + return smallest; } + +minimum([1,10,5,-3,100]); \ No newline at end of file From a0fc3d0824cac0c3d1f0727fc535dcf141aff12a Mon Sep 17 00:00:00 2001 From: khaled-Mohamed1 Date: Thu, 4 Feb 2021 22:20:18 +0300 Subject: [PATCH 2/5] A --- sumOfPairNumber.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 sumOfPairNumber.js diff --git a/sumOfPairNumber.js b/sumOfPairNumber.js new file mode 100644 index 0000000..9873ed6 --- /dev/null +++ b/sumOfPairNumber.js @@ -0,0 +1,53 @@ +/** + * write a function that returns the sum of the pair numbers inside an array + * + * exple sumPair([1,6,100,346,761,249])=>452 + * + * sumPair([2,4,9,73])=>6 + */ +function sumPair(array) { + + let total = 0 + + if(Array.isArray(array)){ // for array + for(i of array){ + if(i % 2 == 0){ + total = total + i + } + } + return total + }else if(typeof array == "object"){ // can replace it by if(true) it works too for object + for(let key in array){ + if(array[key] % 2 == 0){ + total = total + array[key] + }; + } + return total + } +} +console.log(sumPair([1,6,100,346,761,249])); +console.log(sumPair({ + a:2, + b:5, + c:8, + d:10 +})); + +/** + * bonus points + * + * same function works for both arrays and objects + * + * if the input is an array return the sum of the pair numbers + * + * if it is an object like this: + * + * obj={ + * a:2, + * b:5, + * c:8 + * } + * + * return => "a & c have pair values" + * + */ From 5a3db0ba520c7eed065a91e90fa179376e940e23 Mon Sep 17 00:00:00 2001 From: KhaledMohammed Date: Thu, 4 Feb 2021 22:25:13 +0300 Subject: [PATCH 3/5] Update sumOfPairNumber.js --- sumOfPairNumber.js | 88 ++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/sumOfPairNumber.js b/sumOfPairNumber.js index 9873ed6..65b5fdb 100644 --- a/sumOfPairNumber.js +++ b/sumOfPairNumber.js @@ -4,50 +4,52 @@ * exple sumPair([1,6,100,346,761,249])=>452 * * sumPair([2,4,9,73])=>6 - */ + */ function sumPair(array) { - let total = 0 + let total = 0 - if(Array.isArray(array)){ // for array - for(i of array){ - if(i % 2 == 0){ - total = total + i - } - } - return total - }else if(typeof array == "object"){ // can replace it by if(true) it works too for object - for(let key in array){ - if(array[key] % 2 == 0){ - total = total + array[key] - }; - } - return total - } -} -console.log(sumPair([1,6,100,346,761,249])); -console.log(sumPair({ - a:2, - b:5, - c:8, - d:10 -})); + if(Array.isArray(array)){ // for array + for(i of array){ + if(i % 2 == 0){ + total = total + i + } + } + return total + }else if(typeof array == "object"){ // can replace it by if(true) it works too for object + for(let key in array){ + if(array[key] % 2 == 0){ + total = total + array[key] + }; + } + return total + } } + function sumPair(array) { + + } + console.log(sumPair([1,6,100,346,761,249])); + console.log(sumPair({ + a:2, + b:5, + c:8, + d:10 + })); + /** + * bonus points + * + * same function works for both arrays and objects + * + * if the input is an array return the sum of the pair numbers + * + * if it is an object like this: + * + * obj={ + * a:2, + * b:5, + * c:8 + * } + * + * return => "a & c have pair values" + * + */ -/** - * bonus points - * - * same function works for both arrays and objects - * - * if the input is an array return the sum of the pair numbers - * - * if it is an object like this: - * - * obj={ - * a:2, - * b:5, - * c:8 - * } - * - * return => "a & c have pair values" - * - */ From c4f7838e37a4def8b2bf8ed8e5826d096645a0cf Mon Sep 17 00:00:00 2001 From: KhaledMohammed Date: Thu, 4 Feb 2021 22:28:11 +0300 Subject: [PATCH 4/5] Update sumOfPairNumber.js --- sumOfPairNumber.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/sumOfPairNumber.js b/sumOfPairNumber.js index 65b5fdb..629e016 100644 --- a/sumOfPairNumber.js +++ b/sumOfPairNumber.js @@ -9,24 +9,24 @@ function sumPair(array) { let total = 0 - if(Array.isArray(array)){ // for array - for(i of array){ - if(i % 2 == 0){ - total = total + i + if(Array.isArray(array)){ // for array + for(i of array){ + if(i % 2 == 0){ + total = total + i + } } - } - return total - }else if(typeof array == "object"){ // can replace it by if(true) it works too for object - for(let key in array){ - if(array[key] % 2 == 0){ - total = total + array[key] - }; - } - return total - } } - function sumPair(array) { + return total + }else if(typeof array == "object"){ // can replace it by if(true) it works too for object + for(let key in array){ + if(array[key] % 2 == 0){ + total = total + array[key] + }; + } + return total + } +} - } + console.log(sumPair([1,6,100,346,761,249])); console.log(sumPair({ a:2, From 73b2ce0c0b7f4a10a13fe74bc74b745bd9252fdb Mon Sep 17 00:00:00 2001 From: KhaledMohammed Date: Thu, 4 Feb 2021 22:49:51 +0300 Subject: [PATCH 5/5] Update sumOfPairNumber.js --- sumOfPairNumber.js | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/sumOfPairNumber.js b/sumOfPairNumber.js index 629e016..9c38049 100644 --- a/sumOfPairNumber.js +++ b/sumOfPairNumber.js @@ -6,34 +6,30 @@ * sumPair([2,4,9,73])=>6 */ function sumPair(array) { - let total = 0 - - if(Array.isArray(array)){ // for array - for(i of array){ - if(i % 2 == 0){ - total = total + i - } + if(Array.isArray(array)){ // for array + for(i of array){ + if(i % 2 == 0){ + total = total + i } - return total - }else if(typeof array == "object"){ // can replace it by if(true) it works too for object - for(let key in array){ - if(array[key] % 2 == 0){ - total = total + array[key] - }; - } - return total - } + } + return total + }else if(typeof array == "object"){ // can replace it by if(true) it works too for object + for(let key in array){ + if(array[key] % 2 == 0){ + total = total + array[key] + }; + } + return total + } } - - - console.log(sumPair([1,6,100,346,761,249])); - console.log(sumPair({ - a:2, - b:5, - c:8, - d:10 - })); +console.log(sumPair([1,6,100,346,761,249])); +console.log(sumPair({ + a:2, + b:5, + c:8, + d:10 +})); /** * bonus points *