Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d09134a

Browse files
committed
pairs negative and positive
1 parent cce9dab commit d09134a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
function pairsOfNegativeAndPositives(array) {
3+
let hm = new Map();
4+
let resultArray = [];
5+
for (let index = 0; index < array.length; index++) {
6+
if (!hm.has(Math.abs(array[index]))) hm.set(Math.abs(array[index]), 1);
7+
else resultArray.push(Math.abs(array[index]));
8+
}
9+
resultArray.sort((a, b) => a - b);
10+
for (let index = 0; index < resultArray.length; index++) {
11+
console.log(-resultArray[index], resultArray[index])
12+
}
13+
}
14+
let array = [4, 8, 9, -4, 1, -1, -8, -9];
15+
console.log('Negative and Positive Pairs are ');
16+
pairsOfNegativeAndPositives(array)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /