Skip to content

Instantly share code, notes, and snippets.

@withinboredom
Created August 28, 2014 16:42
Show Gist options
  • Save withinboredom/fb8842a52d025c474b30 to your computer and use it in GitHub Desktop.
Save withinboredom/fb8842a52d025c474b30 to your computer and use it in GitHub Desktop.
var summer = function(old_sum, old_input) {
return old_sum + (old_input % 10);
}
var reducer = function(old_input) {
return old_input / 10;
}
var calculateSum = function(input) {
var sum = 0;
while (input > 0) {
sum += summer(sum, input);
input = reducer(input);
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment