Special Sort

Problem

If N integers are entered, you must sort the entered values.
Negative integers must be on the front and positive integers on the back. Also, the order of positive and negative integers should not change.

input

Integer N (5<=N<=100) is given to the first line, and integers including negative numbers are given from the next line. The number 0 is not entered.

8

1 2 3 -3 -2 5 6 -6

output

Print the sorted results.

-3 -2 -6 1 2 3 5 6

Solution

function solution(arr) {
	let answer = arr;

	for (let i = arr.length - 1; i >= 1; i--) {
		for (let j = i - 1; j >= 0; j--) {
			if (arr[i] < 0 && arr[j] > 0) {
				[arr[i], arr[j]] = [arr[j], arr[i]];
			}
		}
	}

	return answer;
}
function solution(arr) {
	let answer = arr;

	for (let i = 0; i < arr.length - 1; i++) {
		for (let j = 0; j < arr.length - i - 1; j++) {
			if (arr[j] > 0 && arr[j + 1] < 0) {
				[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
			}
		}
	}

	return answer;
}