All files / datamodel/src/operator row-diffset-iterator.js

100% Statements 9/9
100% Branches 6/6
100% Functions 2/2
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23                222x 218x 218x 253x 253x 253x 253x 252x 715x            
/**
 * Iterates through the diffSet array and call the callback with the current
 * index.
 *
 * @param {string} rowDiffset - The row diffset string e.g. '0-4,6,10-13'.
 * @param {Function} callback - The callback function to be called with every index.
 */
export function rowDiffsetIterator (rowDiffset, callback) {
    if (rowDiffset.length > 0) {
        const rowDiffArr = rowDiffset.split(',');
        rowDiffArr.forEach((diffStr) => {
            const diffStsArr = diffStr.split('-');
            const start = +(diffStsArr[0]);
            const end = +(diffStsArr[1] || diffStsArr[0]);
            if (end >= start) {
                for (let i = start; i <= end; i += 1) {
                    callback(i);
                }
            }
        });
    }
}