Skip to content

Instantly share code, notes, and snippets.

@beautyfree
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beautyfree/9139193 to your computer and use it in GitHub Desktop.
Save beautyfree/9139193 to your computer and use it in GitHub Desktop.
/**
* Your solution
* @date JS Date object
**/
function solution(date){
date = new Date(Date.parse(date));
return summate(date.getDate().toString() + (date.getMonth()+1).toString() + date.getFullYear().toString());
}
function summate(str_sum) {
str_sum = str_sum.toString().split('');
console.log(str_sum);
var sum = 0;
for(var i=0; i < str_sum.length; i++) {
sum += str_sum[i];
if(sum >= 10) {
sum = summate(sum);
}
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment