2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -0,0 +1,6 @@
|
|||
function sumDigits(n) {
|
||||
n += ''
|
||||
for (var s=0, i=0, e=n.length; i<e; i+=1) s+=parseInt(n.charAt(i),36)
|
||||
return s
|
||||
}
|
||||
for (var n of [1, 12345, 0xfe, 'fe', 'f0e', '999ABCXYZ']) document.write(n, ' sum to ', sumDigits(n), '<br>')
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
// digitsSummed :: (Int | String) -> Int
|
||||
function digitsSummed(number) {
|
||||
|
||||
// 10 digits + 26 alphabetics
|
||||
// give us glyphs for up to base 36
|
||||
var intMaxBase = 36;
|
||||
|
||||
return number
|
||||
.toString()
|
||||
.split('')
|
||||
.reduce(function (a, digit) {
|
||||
return a + parseInt(digit, intMaxBase);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
// TEST
|
||||
|
||||
return [1, 12345, 0xfe, 'fe', 'f0e', '999ABCXYZ']
|
||||
.map(function (x) {
|
||||
return x + ' -> ' + digitsSummed(x);
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue