permutationEquation.js

    0

    0

    The permutation equation calculates the permutation of an array. The index of an element is incremented by 1 and then added to the index of the element preceding it in the array.

    function permutationEquation(p) {
      const arr=[];
    
      for (let i = 1; i <= p.length; i++) {
        arr.push(p.indexOf(p.indexOf(i)+1)+1);
      }
    
      return arr
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.