Move negative to the beginning

An array has both positive and negative numbers in random order. Rearrange the array elements to move all negative numbers before all positive numbers.

Hint

Start with a counter, 'j', set to 0. Go through each item in the list from the beginning to the end. If the current item is negative, swap the current item with the item at position 'j', and increase the counter 'j' by 1. If the current item is not negative, move on to the next item in the list.

# Python implementation
ls = [-1, 2, 6, -7, -8, 9, 3, -4, -5]
j = 0

for i in range(len(ls)):
  item = ls[i]
  if item < 0:
    ls[i] = ls[j]
    ls[j] = item
    j += 1

print(ls)
// Javascript implementation
const list = [-1, 2, 6, -7, -8, 9, 3, -4, -5];
let j = 0;

for (let i = 0; i < list.length; i++) {
  const item = list[i];

  if (item < 0) {
    list[i] = list[j];
    list[j] = item;
    j++;
  }
}

console.log(list);