We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f0f1ca5 commit 59ee591Copy full SHA for 59ee591
scripts/algorithms/S/Sign of the Product of an Array/Sign of the Product of an Array.js
@@ -1,10 +1,12 @@
1
+// Runtime: 83 ms (Top 65.37%) | Memory: 43.7 MB (Top 52.05%)
2
+
3
var arraySign = function(nums) {
- // use filter to find total negative numbers in the array
4
+ // use filter to find total negative numbers in the array
5
let negativeCount = nums.filter(n => n<0).length;
-
- // check if the nums array has zero. If it does, then return 0
6
7
+ // check if the nums array has zero. If it does, then return 0
8
if(nums.includes(0)) return 0;
- // If negativeCount variable is even answer is 1 else -1
9
10
+ // If negativeCount variable is even answer is 1 else -1
11
return negativeCount % 2 === 0 ? 1 : -1
-};
12
+};
0 commit comments