I defined a lambda s, that takes an array x, and sever (slices) it into smaller pieces where the following element would be greater than. Pretty much what the challenge asked for. This is code-golf, so the shortest code in bytes wins.Ī=>a.map((n,i)=>a],i+1]>n&(o=x,r=),r=o=)&xĬonsole.log(JSON.stringify(f())) Hopefully these cover all edge cases: -> The absolute value of each integer will always be less than 2 31.The input array will never be empty, but may contain negatives and/or duplicates.Input and output may be given through any standard methods, and may be in any reasonable array format.Repeat this procedure enough times and the array will be fully sorted. This should be what your program outputs/function returns. Next, reverse each array: įinally, concatenate them all together: Given a non-empty array of integers, e.g.: įirst sever it into arrays where no item is larger than the previous (i.e.
0 Comments
Leave a Reply. |