Positives and Negatives

Published by bangyen in

Create a function which validates whether a given array alternates between positive and negative numbers.

Examples

alternateSign([3, -2, 5, -5, 2, -8]) ➞ true

alternateSign([-6, 1, -1, 4, -3]) ➞ true

alternateSign([4, 4, -2, 3, -6, 10]) ➞ false

Notes

  • Lists can be of any length.
  • It doesn't matter if an array begins/ends with a positive or negative, as long as it alternates.
  • If a list contains 0, return false (as it is neither positive nor negative).
Watch a quick demo on how Edabit works.