Skip to content

Instantly share code, notes, and snippets.

@forrest-akin
Created September 27, 2020 21:05
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 forrest-akin/a14bddd0c8061bc4cbfafef84de43d39 to your computer and use it in GitHub Desktop.
Save forrest-akin/a14bddd0c8061bc4cbfafef84de43d39 to your computer and use it in GitHub Desktop.
const findPoisonedDuration =
( timeSeries , duration ) =>
timeSeries.reduce( sumByCappedDelta( duration ) , 0 )
const sumByCappedDelta =
( max , t1 = -max ) => ( sum , t2 ) =>
( dt = t2 - t1
, t1 = t2
, sum + Math.min( dt , max ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment