Last active
August 29, 2015 13:56
-
-
Save beautyfree/9139193 to your computer and use it in GitHub Desktop.
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
/** | |
* 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