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
}