[Question]
  [
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
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 2 bytes
Code:
```
t0
```
Explanation:
```
t   # Trim off...
 0  #  zero at both sides
```
[Try it online!](http://jelly.tryitonline.net/#code=dDA&input=&args=WzAsIDAsIDAsIDgsIDEsIDQsIDMsIDUsIDAsIDYsIDQsIDEsIDIsIDAsIDAsIDAsIDBd)
[Answer]
# 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>
```
[Answer]
# Retina, 12 bytes
```
^0 ?
)` 0$
```
The trailing linefeed is significant.
Thanks to [@Martin Büttner](https://codegolf.stackexchange.com/users/8478/martin-b%C3%BCttner) and [@FryAmTheEggman](https://codegolf.stackexchange.com/users/31625/fryamtheeggman) for saving a few bytes.
[Try it online](http://retina.tryitonline.net/#code=XjAgPwoKKWAgMCQK&input=MCAwIDAgMSAyIDMgMCA0IDUgNiAwIDAgMA)
[Answer]
# 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
```
[Answer]
# [Haskell](https://en.wikipedia.org/wiki/Haskell_(programming_language)), 29 bytes
```
t=f.f;f=reverse.dropWhile(<1)
```
[Answer]
## Pyth, 4 bytes
```
.sQ0
```
Demo:
```
llama@llama:~$ pyth -c .sQ0
[0, 0, 0, 1, 2, 0, 3, 4, 0, 0, 5, 0, 0, 0, 0]
[1, 2, 0, 3, 4, 0, 0, 5]
```
From [Pyth's `rev-doc.txt`](https://github.com/isaacg1/pyth/blob/d0857326708284d884298464363e633e1390b190/rev-doc.txt#L365):
```
.s <seq> <any>
    Strip from A maximal prefix and suffix of A consisting of copies of B.
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
Code:
```
0Û0Ü
```
[Try it online!](http://05ab1e.tryitonline.net/#code=MMObMMOc&input=WzAsIDAsIDAsIDgsIDEsIDQsIDMsIDUsIDAsIDYsIDQsIDEsIDIsIDAsIDAsIDAsIDBd)
Explanation:
```
0Û    # Trim off leading zeroes
  0Ü  # Trim off trailing zeroes
```
Uses CP-1252 encoding.
[Answer]
## Jelly, 10 bytes
```
Uo\U,o\PTị
```
This doesn't use the builtin.
```
Uo\U            Backward running logical OR
    ,           paired with
     o\         Forward running logical OR
       P        Product
        T       All indices of truthy elements
         ị      Index the input at those values.
```
Try it [here](http://jelly.tryitonline.net/#code=VW9cVSxvXFBU4buL&input=&args=WzAsIDQsIDEsIDIsIDAsIDEsIDIsIDAsIDBd).
[Answer]
# R, 43 bytes
```
function(x)x[cummax(x)&rev(cummax(rev(x)))]
```
or as read/write STDIN/STDOUT 
```
x=scan();cat(x[cummax(x)&rev(cummax(rev(x)))])
```
---
This finds the cumulative maximum from the beginning and the end (reversed) string. The `&` operator converts these two vectors to logical one of the same size as `x`, (zeroes will always converted to `FALSE` and everything else to `TRUE`), this way it makes it possible to subset from `x` according to the met conditions.
[Answer]
# Mathematica ~~34~~ 27 bytes
```
#//.{0,a___}|{a___,0}:>{a}&
```
This repeatedly applies replacement rules until such action fails to provide a new output. 7 bytes saved thanks to Alephalpha.
The first rule deletes a zero at the beginning; the second rule deletes a zero at the end of the array.
[Answer]
## 05AB1E, 4 bytes
```
0Û0Ü
```
Basically trimming leading then trailing zeroes of the input, given as an array.
[Try it online !](http://05ab1e.tryitonline.net/#code=MMObMMOc&input=WzAsIDAsIDAsIDgsIDEsIDQsIDMsIDUsIDYsIDQsIDEsIDIsIDAsIDAsIDAsIDBd)
[Answer]
# Perl, 19 + 1 = 20 bytes
```
s/^(0 ?)+|( 0)+$//g
```
Requires `-p` flag:
```
$ perl -pE's/^(0 )+|( 0)+$//g' <<< '0 0 0 1 2 3 4 5 6 0 0 0'
1 2 3 4 5 6
```
[Answer]
## Ruby, ~~49~~ 44 bytes
```
->a{eval ?a+'.drop_while{|i|i<1}.reverse'*2}
```
Thanks to [manatwork](https://codegolf.stackexchange.com/users/4198/manatwork) for chopping off 5 bytes with a completely different method!
This just `drop`s the first element of the array `while` it's 0, reverses the array, repeats, and finally reverses the array to return it to the proper order.
[Answer]
# Perl, 38 bytes
```
$\.=$_}{$\=~s/^(0\n)*|(0\n)*\n$//gs
```
Run with `perl -p`, (3 bytes added for `-p`).
Accepts numbers on STDIN, one per line; emits numbers on STDOUT, one per line, as a well-behaved unix utility should.
Only treats numbers represented exactly by '0' as zeroes; it would be possible to support other representations with a few more bytes in the regex.
Longer version, still to be run with `-p`:
```
    # append entire line to output record separator
    $\.=$_
}{
    # replace leading and trailng zeroes in output record separator
    $\ =~ s/^(0\n)*|(0\n)*\n$//gs
    # output record separator will be implicitly printed
```
Expanded version, showing interactions with -p flag:
```
# implicit while loop added by -p
while (<>) {
    # append line to output record separator
    $\.=$_
}{ # escape the implicit while loop
    # replace leading and traling 
    $\=~s/^(0\n)*|(0\n)*\n$//gs
    # print by default prints $_ followed by
    # the output record separator $\ which contains our answer
    ;print # implicit print added by -p
} # implicit closing brace added by -p
```
[Answer]
## Elixir, 77 bytes
```
import Enum
z=fn x->x==0 end
reverse(drop_while(reverse(drop_while(l,z)),z))
```
l is the array.
Edit:wah! copy/pasta fail. of course one has to import Enum, which raises the byte count by 12 (or use Enum.function\_name, which will make it even longer).
[Answer]
## JavaScript (ES6), 47 bytes
```
a=>a.join(a="").replace(/(^0+|0+$)/g,a).split(a)
```
Where `a` is the array.
[Answer]
# Vitsy, 13 bytes
Vitsy is slowly getting better... (I'm coming for you Jelly. ಠ\_ಠ)
```
1mr1m
D)[X1m]
```
This exits with the array on the stack. For readability, the TryItOnline! link that I have provided below the explanation will output a formatted list.
Explanation:
```
1mr1m
1m      Do the second line of code.
  r     Reverse the stack.
   1m   I'ma let you figure this one out. ;)
D)[X1m]
D       Duplicate the top item of the stack.
 )[   ] If the top item of the stack is zero, do the stuff in brackets.
   X    Remove the top item of the stack.
    1m  Execute the second line of code.
```
Note that this will throw a StackOverflowException for unreasonably large inputs.
[TryItOnline!](http://vitsy.tryitonline.net/#code=MW1yMW1sXFtOYU9dCkQpW1gxbV0&input=&args=MA+MA+Mg+MQ+MA+MA)
[Answer]
# JavaScript (ES6), 34 bytes
```
a=>a.replace(/^(0 ?)*|( 0)*$/g,'')
```
Input and output are in the form of a space-delimited list, such as `"0 4 1 2 0 1 2 4 0"`.
[Answer]
# R, 39 bytes
```
function(x)x[min(i<-which(x>0)):max(i)]
```
Four bytes shorter than [David Arenburg's R answer](https://codegolf.stackexchange.com/a/73745/59052). This implementation finds the first and last index in the array which is greater than zero, and returns everything in the array between those two indices.
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 9 bytes
```
2:"PtYsg)
```
[**Try it online!**](http://matl.tryitonline.net/#code=MjoiUHRZc2cp&input=WzAsIDQsIDEsIDIsIDAsIDEsIDIsIDQsIDBd)
### Explanation
```
2:"     % For loop (do the following twice)
  P     %   Flip array. Implicitly asks for input the first time
  t     %   Duplicate
  Ys    %   Cumulative sum
  g     %   Convert to logical index
  )     %   Apply index
        % Implicitly end for
        % Implicitly display stack contents
```
[Answer]
# Python 3, 48 bytes
```
lambda a:map(int,''.join(map(str,a)).strip('0'))
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 12 bytes
```
{↔a₁.h>0∧}ⁱ²
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRuX/2obcOjpuaaRx3LldISc4pT9ZRqH@7qrH24dcJ/oNyUxEdNjXoZdgZA@dpHjRsPbfr/P1oh2kBHAYIsdBQMdRRMdBSMdRRMdRTMwGygiBFMAQjF6oB1IMtAGCYISQN0DcZgaVOEgFmsQiwA "Brachylog – Try It Online")
The predicate fails in the case of "nothing".
```
  a₁.           Take the longest suffix of
 ↔              the input reversed
     h          the first element of which
      >0        is greater than 0
        ∧       (which is not the output).
{        }ⁱ²    Do it again.
```
If "nothing" has to be some actual value, like an empty list, it's only one more byte:
# [Brachylog](https://github.com/JCumin/Brachylog), 13 bytes
```
{↔a₁.h>0∨Ė}ⁱ²
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRu/6htw6Ompoe7Omsfbp3wv/pR25TER02Nehl2Bo86VhyZVvuoceOhTf//RytEG@goQJCFjoKhjoKJjoKxjoKpjoIZmA0UMYIpAKFYHbAOZBkIwwQhaYCuwRgsbYoQMItViAUA "Brachylog – Try It Online")
If the input can be assumed to contain only single digits, it's quite a bit shorter:
# [Brachylog](https://github.com/JCumin/Brachylog), 6 bytes
```
c↔↔ℕ₁ẹ
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/pfXa6koGunoFRuX/2obcOjpuaaRx3LldISc4pT9ZRqH@7qrH24dcL/5EdtU0CoZeqjpsaHu3b@/x@tEG2gowBBFjoKhjoKJjoKxjoKpjoKZmA2UMQIpgCEYnXAOpBlIAwThKQBugZjsLQpQsAsViEWAA "Brachylog – Try It Online")
[Answer]
## Dyalog APL, 15 bytes
```
{⌽⍵↓⍨+/0=+\⍵}⍣2
               ⍣2     Apply this function twice:
{             }       Monadic function:
           +\⍵        Calculate the running sum.
       +/0=           Compare to zero and sum. Number of leading zeroes.
   ⍵↓⍨               Drop the first that many elements from the array.
 ⌽                   Reverse the result.
```
Try it [here](http://tryapl.org/?a=%28%7B%u233D%u2375%u2193%u2368+/0%3D+%5C%u2375%7D%u23632%290%200%203%201%200%200%204%201%205%209%200%200%200&run).
[Answer]
# Vim 16 Keystrokes
```
i<input><esc>?[1-9]<enter>lD0d/<up><enter>
```
The input is to be typed by the user between `i` and `esc`, and does not count as a keystroke. This assumes that there will be at least one leading and one trailing zero. If that is not a valid assumption, we can use this slightly longer version: (18 Keystrokes)
```
i <input> <esc>?[1-9]<enter>lD0d/<up><enter>
```
[Answer]
## ES6, 51 bytes
```
f=a=>a.map(x=>x?t=++i:f<i++||++f,f=i=0)&&a.slice(f,t)
```
`t` is set to the index after the last non-zero value, while `f` is incremented as long as only zeros have been seen so far.
[Answer]
# [Perl 6](http://perl6.org), 23 bytes
```
{.[.grep(?*):k.minmax]}
{.[minmax .grep(?*):k]}
```
### Usage:
```
# replace the built-in trim subroutine
# with this one in the current lexical scope
my &trim = {.[.grep(?*):k.minmax]}
say trim [0, 0, 0, 8, 1, 4, 3, 5, 6, 4, 1, 2, 0, 0, 0, 0];
# (8 1 4 3 5 6 4 1 2)
say trim [0, 4, 1, 2, 0, 1, 2, 4, 0];
# (4 1 2 0 1 2 4)
say trim [0, 0, 0, 0, 0, 0];
# ()
say trim [3, 4, 5, 0, 0];
# (3 4 5)
say trim [6];
# (6)
```
[Answer]
# Retina, 11 bytes
```
+`^0 ?| 0$
<empty>
```
Quite simple. Recursively replaces zeroes at beginning and end of line.
[Try it online!](http://retina.tryitonline.net/#code=K2BeMCA_fCAwJAo&input=MCAwIDA)
[Answer]
**Python, 84 characters**
```
def t(A):
 if set(A)<={0}:return[]
 for i in(0,-1):
  while A[i]==0:del A[i]
 return A
```
[Answer]
## Javascript (ES6) 40 bytes
```
a=>/^(0,)*(.*?)(,0)*$/.exec(a.join())[2]
```
[Answer]
# PHP, ~~56~~ ~~54~~ 52 bytes
Uses Windows-1252 encoding
String based solution
```
<?=preg_replace(~ÜÒ×ßÏÖÔƒ×ßÏÖÔÛÜ,"",join($argv,~ß));
```
Run like this:
```
echo '<?=preg_replace(~ÜÒ×ßÏÖÔƒ×ßÏÖÔÛÜ,"",join($argv,~ß));' | php -- 0 0 123 234 0 500 0 0 2>/dev/null;echo
```
If your terminal is set to UTF-8, this is the same:
```
echo '<?=preg_replace("#-( 0)+|( 0)+$#","",join($argv," "));' | php -- 0 0 123 234 0 500 0 0 2>/dev/null;echo
```
## Tweaks
* Saved 2 bytes by negating strings and dropping string delimiters
* Saved 2 bytes by using short print tag
]