You’ll either need a recursive function(a function that calls itself as it works through the array) or a while loop that keeps looping until the values are consumed.
var data = 'abcdefghijklmnop'
var processItems = function(values, i) {
if (values.length == 0) return values
console.log(values.slice(0, i))
return values.slice(i)
}
var processValues = function(values) {
values = processItems(values, 4)
values = processItems(values, 3)
if (values.length > 0) {
processValues(values)
}
}
processValues(data)
Can be modified so that it returns an array like ['++++', '+++', '++++'] fairly simply, just need to push things into an array rather that console.logging. slice is a method on strings and arrays so should work if you’re dealing with an arrays too.
Thx mark, I can’t use the second solution because it won’t show parts of the array where it is not a perfect 4 or 3. So if the first or last line has only 1 or 2 iterations, it will not be displayed. Your own solution ignores the “o” and “p” at the end. I will need to use the first option without returns.