Code coverage report for src/atLeastSize.js

Statements: 100% (11 / 11)      Branches: 100% (6 / 6)      Functions: 100% (1 / 1)      Lines: 100% (10 / 10)      Ignored: none     

All files » src/ » atLeastSize.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23            1 7 7 7   7   7 14 14     7        
/**
 * Checks if the iterable has at least n elements.
 * @param {*} xs - The iterable to check.
 * @param {Number} n - The number of elements to check.
 * @returns {Boolean} - True if the iterable has at least n elements.
 */
function atLeastSize(xs, n=0) {
    let iter = xs[Symbol.iterator]();
    let x = iter.next();
    let i = 0;
 
    n = n >= 0 ? n : 0;
 
    while (!x.done && i !== n) {
        i += 1;
        x = iter.next();
    }
 
    return i === n;
}
 
export default atLeastSize;