We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cce9dab commit d09134aCopy full SHA for d09134a
Data-Structure/Hashing/pairsNegativeAndPositive.js
@@ -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)
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments