K
K
kuzubina2021-06-17 08:54:20
JavaScript
kuzubina, 2021-06-17 08:54:20

How to find the maximum number of repetitions in an array of occurrences of words in a string in a row?

I have an array like this

const massive = [
  'Max download report 1',
  'Felix download report 4',
  'Roberto upload report 5',
  'Alex download report 1',
  'Stef download report 2',
  'Sam download report 3',
  'Monika upload report 54'
]


you need to count the maximum number of repetitions of lines in a row with the word download

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-06-17
@kuzubina

arr.reduce((acc, n) => (
  n.includes('download')
    ? acc[acc.length - 1]++
    : acc.push(0),
  acc
), [ 0 ])

What to do next - see my answer to your previous question, think.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question