diff --git a/firstToyProblem.js b/firstToyProblem.js index b0873e7..619f26c 100644 --- a/firstToyProblem.js +++ b/firstToyProblem.js @@ -4,6 +4,31 @@ * without using any pre build in function */ +const myArr = [1, 10, 5, -3, 100]; + +//function to return minValue of array function minimum(array) { - return; + let minValue = array[0]; + for (let count = 1; count < array.length; count++) { + if (array[count] < minValue) { + minValue = array[count]; + } + } + return minValue; +} +//function to return maxValue of array + +/* +function maximum(array) { + let maxValue = array[0]; + for (let count = 1; count < array.length; count++) { + if (array[count] > maxValue) { + maxValue = array[count]; + } + } + return maxValue; } +console.log(maximum(myArr)); +*/ + +console.log(minimum(myArr)); \ No newline at end of file diff --git a/sumOfPairNumber.js b/sumOfPairNumber.js index 82412dc..b6f8d09 100644 --- a/sumOfPairNumber.js +++ b/sumOfPairNumber.js @@ -5,8 +5,23 @@ * * sumPair([2,4,9,73])=>6 */ -function sumPair(array) { - //your code goes here +function sumPair(elements) { + if (Array.isArray(elements) === true) { + let sum = 0; + for (let count = 0; count < elements.length; count++) { + if (elements[count] % 2 === 0) + sum += elements[count]; + } + return sum; + } else { + let str =" " + for (const accessItem in elements) { + if (elements[accessItem] % 2 === 0) { + str+=accessItem+" & "; + } + } + return str+"have pair values"; + } } /** @@ -21,9 +36,23 @@ function sumPair(array) { * obj={ * a:2, * b:5, - * c:8 + * c:8, + * v:4, + * r:33 * } * - * return => "a & c have pair values" + * return => "a & c & v have pair values" * */ +const myArr = [1, 6, 100, 346, 761, 249]; +let obj = { + a: 2, + b: 5, + c: 8, + v: 4, + r:33, + x:100 +} + +console.log(sumPair([1, 6, 100, 346, 761, 249])); +console.log(sumPair(obj)); \ No newline at end of file