Consider the following array :
[500, 250, 380, 250, 230, 100, 700, 900, 200, 100, 10, 800, 5]
My goal is to extract all values less than 350 that are contiguous. Here is the desired result :
[[250], [250, 230, 100], [200, 100, 10], [5]]
This is what I have tried so far:
const result = []
array.forEach((item, index, arr) => {
if (item <= 350 && arr[index + 1] <= 350) {
brokenMeasurements.push(item)
}
})
I am struggling with identifying when the contiguous values end. Currently, this code only retrieves all values under 350.