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
10 changes: 9 additions & 1 deletion firstToyProblem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
27 changes: 25 additions & 2 deletions sumOfPairNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down