Post History
JavaScript, 102 bytes s=>[...x=s.split``].concat(x.reverse()).reduce((l,c,i,a)=>l+` `+(a[i+1]?c+' '.repeat(i-1)+c:a.join``)) The first part creates the 'mirrored' string in an array. red...
Answer
#1: Initial revision
# JavaScript, 102 bytes s=>[...x=s.split``].concat(x.reverse()).reduce((l,c,i,a)=>l+` `+(a[i+1]?c+' '.repeat(i-1)+c:a.join``)) The first part creates the 'mirrored' string in an array. `reduce` starts with the first element (which conveniently handles the top vertex of the triangle) and calls the provided function for each later element, with the arguments being the previous value, the element, its index, and the array. `a[i+1]` is a way of checking for the last element: it is `undefined` (which is falsy) for the last element, and a character (truthy) for the rest.