f=([n,...c]a],b=[0])=>n?b.map(v=>f(ca,[1,...Array(n-2).fill(v),1])):b
Try it online!Try it online!
Commented
f = ( // f is a recursive function taking: [ n, // n = next value from the input list ...a ], // a[] = all remaining values b = [ 0 ] // b[] = output, initialized to [ 0 ] ) => // n ? // if n is defined: b.map(v => // for each value v in b[]: f( // do a recursive call: a, // pass the remaining values [ // build an array consisting of: 1, // a leading '1' ...Array(n - 2) // followed by n - 2 values .fill(v), // set to v 1 // followed by a trailing '1' ] // end of array ) // end of recursive call ) // end of map() : // else: b // we're done: return b[]