DEV Community

Discussion on: Javascript Array Condensing

Collapse
avalander profile image
Avalander • Edited on

Point-free ramda sorcery.

const {
  compose,
  equals,
  flatten,
  partition,
  reverse,
} = require('ramda')

const f = compose(
  flatten,
  reverse,
  partition(equals(0)),
)

f([ 0, 0, 0, 4, 5, 1, 0, 5, 2, 0, 5 ]) // [ 4, 5, 1, 5, 2, 5, 0, 0, 0, 0, 0 ]