Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion firstToyProblem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
37 changes: 33 additions & 4 deletions sumOfPairNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

/**
Expand All @@ -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));