aureooms/js-permutation

View on GitHub
src/apply.js

Summary

Maintainability
A
0 mins
Test Coverage
import {_apply} from './_apply.js';
import {identity} from './identity.js';

/**
 * Apply a given sequence (in the given order) of transpositions (given as
 * index tuples) to the identity permutation over input <code>n</code> elements.
 *
 * @param {number} n The size of the identity permutation to apply the transpositions
 * to.
 * @param {Iterable} transpositions The given transpositions to apply.
 * @returns {Array} The resulting permutation.
 */
export function apply(n, transpositions) {
    const rho = identity(n);

    _apply(transpositions, rho);

    return rho;
}