Skip to content

Commit 860df66

Browse files
authored
Create 1822-sign-of-the-product-of-an-array.js
1 parent 585b834 commit 860df66

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const arraySign = function(nums) {
6+
let pos = 0, neg = 0, zero = 0
7+
for(let e of nums) {
8+
if(e > 0) pos++
9+
else if(e < 0) neg++
10+
else zero++
11+
}
12+
if(zero > 0) return 0
13+
if(neg % 2 === 1) return -1
14+
else return 1
15+
};

0 commit comments

Comments
 (0)