I have an array which I have sorted from smallest integer to largest. The array data comes from backend and will be random numbers
// example array from backend
const arr = [400,30,10,-1]
const sortedArray = arr.sort((a, b) => a - b)
// [-1,10,30,400]
If the first index of the array is equal to -1
I want to remove it from the first position in the array and append it to the last position of the array.
For example if array is [-1, 10, 30, 400]
I want to return [10,30,400,-1]
.
Edit: I am looking for the safest possible way and unsure to use splice(), filter()
etc