arithmetic-operations-for/naturals-big-endian

View on GitHub
src/core/array/_build.js

Summary

Maintainability
A
0 mins
Test Coverage
import assert from 'assert';

export default function _build(base, number, data, n) {
    assert(typeof base === 'number');
    assert(typeof number === 'number');
    assert(n <= data.length);

    let q = number;
    const d = base;

    while (q >= d) {
        data[--n] = q % d;
        q = (q / d) | 0;
    }

    data[--n] = q;

    assert(n >= 0);
    return n;
}