about | help | code help+videos | done | prefs |
Write a method that returns a 'wonky' version of the input parameter array of positive integers. To make the 'wonky' array, only include values that represent increasing positive integer values that are greater than the previous non-zero in the resulting array. If the numbers do not represent an increase, replace them with a zero. For example, the array {125,345,547,539,437,2351} results in {125,345,547,0,0,2351} because 345>125, 547>345, but 539 is not greater than 547, so it is replaced with a zero. 437 is not compared to zero, but instead to the previous non-zero value of 547. Since 437 is not greater than 547 it is also replaced with a zero. Finally 2351 IS greater than 547 so that number is kept. Look at the test data for additional examples. As a precondition you may assume that the input parameter array will have at least one positive integer element. feb13_2020_APP1SLHL_wonky([15, 2, 4, 14, 22, 18, 33, 40]) → [15, 0, 0, 0, 22, 0, 33, 40] feb13_2020_APP1SLHL_wonky([700, 500, 300, 200, 100, 50, 20]) → [700, 0, 0, 0, 0, 0, 0] feb13_2020_APP1SLHL_wonky([421, 532, 457, 532, 865, 532, 6856, 9876, 532, 463]) → [421, 532, 0, 0, 865, 0, 6856, 9876, 0, 0] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 290
Copyright Nick Parlante 2017 - privacy