#JavaScript (Node.js), 125 109 106 bytes#
JavaScript (Node.js), 125 109 106 bytes
-16 18 bytes from Zacharý
-1 by removing {
and }
by changing the incrementer to include the "set last to the current"
m=x=>{z=[[],[]];l=NaN;for(i=0;i<x.length;l=x[i++])if(l>x[i])z[1].push(x[i]);else z[0].push(x[i]);return z}
Basically, asks is the current item greater than the last item, add to the first list. Otherwise, add to the second.
Found out during this that comparing any number to NaN
will always result false
. Interesting!
Explanation:
m = x => { // Create function
z = [[], []]; // Initialize dropsort output
l = NaN; // Initialize last element
for (i = 0; i < x.length; l=x[i++])// For each item in input...
if (l > x[i]) // If current item is greater than previous
z[1].push(x[i]); // Then add it to the first part of output
else // Elsewise
z[0].push(x[i]); // Add it to the nonordered part of the dropsort
// Set last item to current item
} // Repeat
return z // Return finished dropsort
} // End function