Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Digital-root/JavaScript/digital-root.js
Normal file
16
Task/Digital-root/JavaScript/digital-root.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/// Digital root of 'x' in base 'b'.
|
||||
/// @return {addpers, digrt}
|
||||
function digitalRootBase(x,b) {
|
||||
if (x < b)
|
||||
return {addpers:0, digrt:x};
|
||||
|
||||
var fauxroot = 0;
|
||||
while (b <= x) {
|
||||
x = (x / b) | 0;
|
||||
fauxroot += x % b;
|
||||
}
|
||||
|
||||
var rootobj = digitalRootBase(fauxroot,b);
|
||||
rootobj.addpers += 1;
|
||||
return rootobj;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue