Last active
August 29, 2015 14:21
-
-
Save Maximization/9dd45812011b864457d6 to your computer and use it in GitHub Desktop.
Solution to @terakilobyte's problemset, posted at: 12-05-2015 4:05AM GMT+2 in FreeCodeCamp's Slack #general chatroom
This file contains hidden or 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
/* | |
* solved by Maximization on 12 May 2015 | |
* | |
* PROBLEM STATEMENT | |
* I want you to iterate through the range n = (1, 200). If n modulo any key on the object === 0, | |
* I want you to subtract (so the negatives will add, yes) the value the key associates to and tell | |
* me the value after you iterate through the range. Start with a sum of 0. | |
*/ | |
// object to check against | |
var obj = { | |
7: 3, | |
18: 12, | |
14: -5, | |
6: 2, | |
24: -12, | |
11: 1, | |
2: 4, | |
4: -2 | |
}; | |
function moduloSummation(obj, range) { | |
var sum = 0; | |
for (var i = 1; i <= range; i++) { | |
for (var key in obj) { | |
if (key % i === 0) { | |
sum += obj[key]; | |
} | |
} | |
} | |
return sum; | |
} | |
console.log(moduloSummation(obj, 200)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment