Beat 98% in JavaScript
Approach\n Describe your approach to solving the problem. \nYou have initial state which is positive. Iterate through the array. \n- Ignore all positive numbers
# Approach\n<!-- Describe your approach to solving the problem. -->\nYou have initial state which is positive. Iterate through the array. \n- Ignore all positive numbers\n- When you see 0, immediately return 0\n- If it is negative, swap the sign of the state  \n\n# Complexity\n- Time complexity: O(N) in the worst case\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar arraySign = function(nums) {\n    // initial state\n    let isNeg = false;\n    // iterate through the array\n    for(let num of nums) {\n        if(num === 0) return 0;\n        // swap the sign\n        if(num < 0) isNeg = !isNeg;\n    }\n    return isNeg?-1:1;\n};\n```
['Array', 'Math', 'JavaScript']