Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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));
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript date set day of week 
Javascript :: how to detech my cosle errors in angualr 
Javascript :: how to style svgs in react 
Javascript :: Difference b/w AddEventListener and Attach Event 
Javascript :: Private slots are new and can be created via Static initialisation blocks in classes 
Javascript :: mettre en commentaire vscode 
Javascript :: how do i make http post in nodejs without third party 
Javascript :: upload image to server react next 
Javascript :: typeorm with better sqlite using query builder 
Javascript :: how to change default browser in vs code json 
Javascript :: how can click div close and open next day jquery 
Javascript :: socket cheatsheet 
Javascript :: battery status check on user machine 
Javascript :: verify number of times request was made in cypress 
Javascript :: JavaScript Normalized and UnNnormalized URL 
Javascript :: Register post meta of sidebar in wordpress 
Javascript :: convert fetch in axios 
Javascript :: this ....object of. 
Javascript :: is enabled 
Javascript :: intro.js free alternative 
Javascript :: loop data from data base laravel to javascript 
Javascript :: why is table.current.row.length not working 
Javascript :: how i change background of row in javascript jquery 
Javascript :: JS Recursive getLength of Array 
Javascript :: react 1 to 10 rating 
Javascript :: strapi login api location 
Javascript :: javascripts 
Javascript :: summernote click event jquery 
Javascript :: path error 
Javascript :: js merge 2 index declarations for loop 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =