Exercise · Scope · lesson 8 of 8
Exercise: last positive number
Write a function function lastPositive(nums) that returns the last positive number in the array nums. If the array has no positive numbers, the function returns null.
lastPositive([3, -1, 5, -2])→5lastPositive([8, -3, -6])→8lastPositive([-1, 0, -5])→null
Constraints: nums is an array of integers of length 0 to 20; 0 does not count as positive; for an empty array and for an array with no positive numbers the function returns null.
Do not add extra imports unless the task says so explicitly.
Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.