Answers for "will stop the loop if the array has any negative number and return all the positive numbers before the negative numbers"

0

will stop the loop if the array has any negative number and return all the positive numbers before the negative numbers

//will stop the loop if the array has any negative number and return all the positive numbers before the negative numbers
function positiveNums(nums){
    numbers = [];
    for(var i=0;i<nums.length;i++){
        if(nums[i]<0){
            break;
        }
        else{
            numbers.push(nums[i]);
        }
    }
    return numbers;
}
var numbers = [1,2,3,4,5,6,7,43,-1,45,2,3,4,6,7,3];
console.log(positiveNums(numbers));
Posted by: Guest on March-24-2022

Code answers related to "will stop the loop if the array has any negative number and return all the positive numbers before the negative numbers"

Code answers related to "Javascript"

Browse Popular Code Answers by Language