Last active
December 9, 2018 02:54
-
-
Save ronit-mukherjee/804b6e84edb16b7eebab5bbb21cae23c to your computer and use it in GitHub Desktop.
Solution of Program #RMJPQ2 on http://ronitmukherjee.com/javascript-practice-questions/#RMJPQ2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//JS Fiddle Link:- https://jsfiddle.net/mukherjeeronit/ac1nvp6j/ | |
function sumOfAllEvenNumbers(arr) { | |
var sum = 0; | |
for (var i = 0; i < arr.length; i++) { | |
isEven(arr[i], function(response) { | |
if (response === true) { | |
sum += arr[i]; | |
} | |
}); | |
} | |
return sum; | |
} | |
function isEven(num, callback) { | |
if (num % 2 === 0) { | |
callback(true); | |
} else { | |
callback(false); | |
} | |
} | |
var arr = [10, 3, 9, 6, 11, 20]; | |
var sum = sumOfAllEvenNumbers(arr); | |
console.log("sum of all even numbers = " + sum); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment