JSFiddle - React, Tailwind, and code Playground

by Jessie Lau

JavaScript

function removeNegatives(arr) {
    arr.sort(function (a, b) {
        return b - a;
    });    
    while(arr.length > 0 && arr[arr.length-1] < 0){
    	arr.pop();
    }
    return arr;
}
console.log(removeNegatives([-3, -4, 5, -10, 1, 3, 2, 10]));