Skip to content

Commit d221f2f

Browse files
committed
Added Sequence-Equation problem solution
1 parent ff00efe commit d221f2f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Sequence Equation/main.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env node
2+
3+
// Problem Description at -> https://www.hackerrank.com/challenges/permutation-equation/problem
4+
5+
function permutationEquation(p) {
6+
const output = [];
7+
for (let i = 1; i <= p.length; i++) {
8+
const p_x = p.indexOf(i) + 1;
9+
output.push(p.indexOf(p_x) + 1);
10+
}
11+
12+
return output;
13+
}
14+
15+
console.log(permutationEquation([2, 3, 1])); // 2, 3, 1
16+
// console.log(permutationEquation([4, 3, 5, 1, 2])); // 1, 3, 5, 4, 2

0 commit comments

Comments
 (0)