Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 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');
|
||||
|
||||
})();
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
(() => {
|
||||
"use strict";
|
||||
|
||||
// -------------- INTEGER DIGITS SUMMED --------------
|
||||
|
||||
// digitsSummed :: (Int | String) -> Int
|
||||
const digitsSummed = number => {
|
||||
|
||||
// 10 digits + 26 alphabetics
|
||||
// give us glyphs for up to base 36
|
||||
const intMaxBase = 36;
|
||||
|
||||
return `${number}`
|
||||
.split("")
|
||||
.reduce(
|
||||
(sofar, digit) => sofar + parseInt(
|
||||
digit, intMaxBase
|
||||
),
|
||||
0
|
||||
);
|
||||
};
|
||||
|
||||
// ---------------------- TEST -----------------------
|
||||
return [1, 12345, 0xfe, "fe", "f0e", "999ABCXYZ"]
|
||||
.map((x) => `${x} -> ${digitsSummed(x)}`)
|
||||
.join("\n");
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue