• + 0 comments

    using reduce in JS/Javascript:-

    function permutationEquation(p) {
       return p.reduce((acc, _, index) => {
        acc.push(p.indexOf(p.indexOf(index + 1) + 1) + 1)
        return acc
       }, [])
    }