Skip to content

Instantly share code, notes, and snippets.

@goofballLogic
Created February 16, 2026 09:40
Show Gist options
  • Select an option

  • Save goofballLogic/02ffef98a9fce78f4039581c57c1e472 to your computer and use it in GitHub Desktop.

Select an option

Save goofballLogic/02ffef98a9fce78f4039581c57c1e472 to your computer and use it in GitHub Desktop.
const swap = (xs, n, i) =>
xs.fill(
xs.splice(i+1, 1, n)[0],
i,
i+1
)
;
const chase = (xs, n, i) =>
i === xs.length - 1
? xs
: chase(
swap(xs, n, i),
n,
++i
)
;
const chaseIfN = (xs, n, i) =>
xs[i] === n
? chase(xs, n, i)
: xs
;
const moveNums = (xs, n, i = 0) =>
i === xs.length ?
xs :
moveNums(
chaseIfN(xs, n, i),
n,
++i
)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment