Skip to content

Instantly share code, notes, and snippets.

@neharkarvishal
Created May 21, 2020 14:32
Show Gist options
  • Save neharkarvishal/f4ff4057d015c717009fa95f6f6adba4 to your computer and use it in GitHub Desktop.
Save neharkarvishal/f4ff4057d015c717009fa95f6f6adba4 to your computer and use it in GitHub Desktop.
/**
* getNumberOfDigits.js
* tags: { JavaScript, Array, RxJS }
*/
const { interval } = Rx;
const { scan, pluck, groupBy } = RxOperators;
interval(1000).pipe(
scan(
({ secondLast, last }) => ({ secondLast: last, last: last + secondLast }),
{ secondLast: 0, last: 1 }
),
pluck("secondLast"),
groupBy(n => Math.floor(Math.log10(n)))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment