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 diff --git a/sumOfPairNumber.js b/sumOfPairNumber.js index 82412dc..394074b 100644 --- a/sumOfPairNumber.js +++ b/sumOfPairNumber.js @@ -6,10 +6,33 @@ * sumPair([2,4,9,73])=>6 */ function sumPair(array) { - //your code goes here + 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