Given a non-empty list/array containing only non-negative integers like this:
[0, 0, 0, 8, 1, 4, 3, 5, 6, 4, 1, 2, 0, 0, 0, 0]
Output the list with trailing and leading zeroes removed.
The output for this would be:
[8, 1, 4, 3, 5, 6, 4, 1, 2]
Some other test cases:
[0, 4, 1, 2, 0, 1, 2, 4, 0] > [4, 1, 2, 0, 1, 2, 4]
[0, 0, 0, 0, 0, 0] > nothing
[3, 4, 5, 0, 0] > [3, 4, 5]
[6] > [6]
Shortest code wins
Nil
()
/[]
slip()
/Empty
Any
{}
some of them are undefined, some defined but singular, some that slip into other lists such that they don't increase the number of elements. ( There are as many different variations onAny
as there are classes/types and roles ) \$\endgroup\$"0,4,1,2,0,1,2,4,0" => "4,1,2,0,1,2,4"
EDIT: Just noticed many languages do this already. \$\endgroup\$