Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active January 27, 2022 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/648bad6653de48806da44b8db91f2f35 to your computer and use it in GitHub Desktop.
Save McLarenCollege/648bad6653de48806da44b8db91f2f35 to your computer and use it in GitHub Desktop.
Print Subarray Until Negative

Given the following nested array write code that prints all the non-negative numbers in each sub-array that occur before a negative number.

Tip: First do it for the first subarray and then write a loop to do it for all the subarrays

CODE TEMPLATE


function printUntilNegative(arr){
// write your code here
}
let arr = [[1,2,-3,5],[5,0,-4,7,8],[-1,5,6],[4,5,-6,8,-9]];
printUntilNegative(arr);// should print 1 2 5 0 4 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment