Remove leading and trailing zeroes
Jelly, 2 bytes
Code:
t0
Explanation:
t # Trim off...
0 # zero at both sides
Try it online!
JavaScript (ES6) 43
a=>(f=a=>a.reverse().filter(x=>a|=x))(f(a))
Less golfed
a=>{
f=a=>a.reverse().filter(x=>a|=x) // reverse and remove leading 0
// leverage js cast rules: operator | cast operands to integer
// an array casted to integer is 0 unless the array is made of
// a single integer value (that is ok for me in this case)
return f(f(a)) // apply 2 times
}
Test
F=a=>(f=a=>a.reverse().filter(x=>a|=x))(f(a))
function test(){
var l=(I.value.match(/\d+/g)||[]).map(x=>+x)
O.textContent=F(l)
}
test()
#I { width:90%}
<input id=I oninput='test()' value='0 0 1 3 7 11 0 8 23 0 0 0'>
<pre id=O></pre>
CJam, 13 bytes
l~{_{}#>W%}2*
With the array inputted.
Longer version:
l~ Puts input on the stack and parse as array
{ } Code block
_ Duplicate the first thing on the stack
{}# Finds the index of the first non-0 value in the array, puts it on the stack
> Slices the array from that index
W% Reverses the array
2* Does the code block twice in total