computational-combinatorics/permutation

View on GitHub
src/compose.js

Summary

Maintainability
A
0 mins
Test Coverage
import {_compose} from './_compose.js';
import {permutation} from './permutation.js';

/**
 * Compose two input permutations. The resulting permutation is output as an
 * array of indices.
 *
 * @param {Array} sigma The first input permutation.
 * @param {Array} tau The second input permutation.
 * @returns {Array} The resulting permutation as an array.
 */
export function compose(sigma, tau) {
    // TODO replace with Array.from( _compose...

    const rho = permutation(sigma.length);

    let i = 0;

    for (const r of _compose(sigma, tau)) {
        rho[i] = r;
        ++i;
    }

    return rho;
}