Write a function groupNegatives(numbers) that returns a new array with the negative numbers on the left: first all negative numbers, then all other numbers.
numbers is an array of integers. It can be empty.0 is not negative: it goes to the right group, together with the positive numbers.numbers. [-5, 10, -3, 8, -1, 6] gives [-5, -3, -1, 10, 8, 6]. Do not sort the numbers.numbers.Each element goes to one of two groups. filter can pick the elements of one group.
groupNegatives([-5, 10, -3, 8, -1, 6])Returns [ -5, -3, -1, 10, 8, 6 ]
groupNegatives([4, -7, 0, 2])Returns [ -7, 4, 0, 2 ]
Asked at ServiceNow · Source
groupNegatives([ -5, 10, -3, 8, -1, 6 ])[ -5, -3, -1, 10, 8, 6 ]groupNegatives([ 4, -7, 2 ])[ -7, 4, 2 ]Hidden tests run on Submit.