Skip to content

how to find subarray? #3386

Answered by bunglegrind
WingDust asked this question in Q&A
Discussion options

You must be logged in to vote

quick and dirty

const isStart = ([f, s]) => f === 0 && s !== 0;
const isEnd = ([f, s]) => f !== 0 && s === 0;
const reduceIndexed = R.addIndex(R.reduce);

reduceIndexed((acc, item, index)  =>  (
    isStart(item)
    ? [...acc, index]
    : (
       isEnd(item)
       ?  [...acc, index + 1]
       : acc
      )
), [], R.aperture(2, y));

REPL

I suppose a better solution is achievable by employing transducers

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by WingDust
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants