Skip to content

Commit 2ad6b6d

Browse files
committed
sumindice
1 parent d096b73 commit 2ad6b6d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Programs/Array/sumindices.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// "Find all pairs of elements in the array whose sum is equal to 10, and return their indices.
2+
3+
const arr = [8, 1, 5, 4, 6, 11];
4+
const ans = [];
5+
for (let i = 0; i < arr.length - 1; i++) {
6+
for (let j = i + 1; j < arr.length; j++) {
7+
if (arr[i] + arr[j] == 10) {
8+
ans.push(i);
9+
ans.push(j);
10+
}
11+
}
12+
}
13+
console.log(ans);

0 commit comments

Comments
 (0)