Skip to main content
Commonmark migration
Source Link

#JavaScript (ES6), 103 bytes

JavaScript (ES6), 103 bytes

v=>(v=v.split` `).map(_=>v=v.map((x,i)=>v[++i]?x.slice(0,n=v[i].length,v[i]+=x.slice(n)):x))&&v.join` ` 

Split on CR, outer map ensures we loop enough times to allow "gravity" to drop letters as far as they need to drop.

Inner map first checks if there is a next line, if so, and it is shorter, drop the overflow to the next line. i.e if the 1st line has "ABCD" and the 2nd line has "FG", drop the "CD" from 1st line to the 2nd so that the 1st line becomes "AB" and the 2nd becomes "FGCD".

As we do this as many times as there are lines, the letters drop as far as they should, leaving us with the desired outcome.

#JavaScript (ES6), 103 bytes

v=>(v=v.split` `).map(_=>v=v.map((x,i)=>v[++i]?x.slice(0,n=v[i].length,v[i]+=x.slice(n)):x))&&v.join` ` 

Split on CR, outer map ensures we loop enough times to allow "gravity" to drop letters as far as they need to drop.

Inner map first checks if there is a next line, if so, and it is shorter, drop the overflow to the next line. i.e if the 1st line has "ABCD" and the 2nd line has "FG", drop the "CD" from 1st line to the 2nd so that the 1st line becomes "AB" and the 2nd becomes "FGCD".

As we do this as many times as there are lines, the letters drop as far as they should, leaving us with the desired outcome.

JavaScript (ES6), 103 bytes

v=>(v=v.split` `).map(_=>v=v.map((x,i)=>v[++i]?x.slice(0,n=v[i].length,v[i]+=x.slice(n)):x))&&v.join` ` 

Split on CR, outer map ensures we loop enough times to allow "gravity" to drop letters as far as they need to drop.

Inner map first checks if there is a next line, if so, and it is shorter, drop the overflow to the next line. i.e if the 1st line has "ABCD" and the 2nd line has "FG", drop the "CD" from 1st line to the 2nd so that the 1st line becomes "AB" and the 2nd becomes "FGCD".

As we do this as many times as there are lines, the letters drop as far as they should, leaving us with the desired outcome.

Remove extraneous characters
Source Link
Grax32
  • 1.3k
  • 7
  • 10

#JavaScript (ES6), 105103 bytes

v=>(v=v.split` `).map(_=>v=v.map((x,i)=>v[++i]?x.slice(0,(n=v[i].length),v[i]+=x.slice(n)):x))&&v.join` ` 

Split on CR, outer map ensures we loop enough times to allow "gravity" to drop letters as far as they need to drop.

Inner map first checks if there is a next line, if so, and it is shorter, drop the overflow to the next line. i.e if the 1st line has "ABCD" and the 2nd line has "FG", drop the "CD" from 1st line to the 2nd so that the 1st line becomes "AB" and the 2nd becomes "FGCD".

As we do this as many times as there are lines, the letters drop as far as they should, leaving us with the desired outcome.

#JavaScript (ES6), 105 bytes

v=>(v=v.split` `).map(_=>v=v.map((x,i)=>v[++i]?x.slice(0,(n=v[i].length),v[i]+=x.slice(n)):x))&&v.join` ` 

Split on CR, outer map ensures we loop enough times to allow "gravity" to drop letters as far as they need to drop.

Inner map first checks if there is a next line, if so, and it is shorter, drop the overflow to the next line. i.e if the 1st line has "ABCD" and the 2nd line has "FG", drop the "CD" from 1st line to the 2nd so that the 1st line becomes "AB" and the 2nd becomes "FGCD".

As we do this as many times as there are lines, the letters drop as far as they should, leaving us with the desired outcome.

#JavaScript (ES6), 103 bytes

v=>(v=v.split` `).map(_=>v=v.map((x,i)=>v[++i]?x.slice(0,n=v[i].length,v[i]+=x.slice(n)):x))&&v.join` ` 

Split on CR, outer map ensures we loop enough times to allow "gravity" to drop letters as far as they need to drop.

Inner map first checks if there is a next line, if so, and it is shorter, drop the overflow to the next line. i.e if the 1st line has "ABCD" and the 2nd line has "FG", drop the "CD" from 1st line to the 2nd so that the 1st line becomes "AB" and the 2nd becomes "FGCD".

As we do this as many times as there are lines, the letters drop as far as they should, leaving us with the desired outcome.

Source Link
Grax32
  • 1.3k
  • 7
  • 10

#JavaScript (ES6), 105 bytes

v=>(v=v.split` `).map(_=>v=v.map((x,i)=>v[++i]?x.slice(0,(n=v[i].length),v[i]+=x.slice(n)):x))&&v.join` ` 

Split on CR, outer map ensures we loop enough times to allow "gravity" to drop letters as far as they need to drop.

Inner map first checks if there is a next line, if so, and it is shorter, drop the overflow to the next line. i.e if the 1st line has "ABCD" and the 2nd line has "FG", drop the "CD" from 1st line to the 2nd so that the 1st line becomes "AB" and the 2nd becomes "FGCD".

As we do this as many times as there are lines, the letters drop as far as they should, leaving us with the desired outcome.