Skip to content

Instantly share code, notes, and snippets.

@otobrglez
Created January 28, 2022 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otobrglez/ad26060734faa550783836f95ec63009 to your computer and use it in GitHub Desktop.
Save otobrglez/ad26060734faa550783836f95ec63009 to your computer and use it in GitHub Desktop.
Word sequence puzzle
const assert = require('assert');
const sequence = (string) => string.split(/(?<=(.))(?!\1|$)/g)
.filter((_, i) => !(i % 2))
.map((c) => [c.length, c[0]])
.flatMap((c) => c)
.join('')
assert.equal(sequence("AAABBAAC"),"3A2B2A1C")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment