Ad
  • Custom User Avatar

    I just tested it again in codewars with 10,000,000,000 and it still works fine. I also tried with other several higher numbers and it always works fine and returns the expected value:

    • 92,000,000,123 and returned 8 (true)
    • 999,999,999,999 and returned 9 (true)
    • 9,111,999,999,999 and returned 3 (true)
    • 88,888,888,888,888 and returned 4 (true)
    • 123,123,123,123,123 and returned 3 (true)
    • 123,456,789,012,345 and returned 6 (true)

    Here you can try the tests:

    const chai = require("chai");
    const assert = chai.assert;
    chai.config.truncateThreshold=0;
    
    describe("Tests", () => {
      it("test", () => {
        assert.strictEqual( digitalRoot(10000000001), 2)
        assert.strictEqual( digitalRoot(92000000123), 8)
        assert.strictEqual( digitalRoot(999999999999), 9)
        assert.strictEqual( digitalRoot(9111999999999), 3)
        assert.strictEqual( digitalRoot(88888888888888), 4)
        assert.strictEqual( digitalRoot(123123123123123), 3)
        assert.strictEqual( digitalRoot(123456789012345), 6)
      });
    });
    
  • Custom User Avatar

    This dude must be a scientist in NASA