If I have an array with only one value for each key and I want to add the length of every three values together, how can this be accomplished?
I tried using reduce, but this seems to only be able to add two values at a time. I’ve tried concat so I can then add all of the contaminated values by getting the length of the new single value, but I need to contact every 3 values in a given array regardless of the values length or the array’s length. Since I’m unable to use functions inside of for loops, I can’t use a for loop to loop through each key via a for of loop or a for each loop.
I don’t want the coding answer written out for me, I just want some ideas of what methods I should be looking at. if I write a function, that function will be a sub-function of my current function. If possible, I’d like an idea that could allow for more than every 3 values based on the length of the word given to my current loop that converts the letters to morse code values. Meaning I can’t just say if less than 3 add. I also can’t say if .length is less than 3 … 6… 9… etc. because the value provided may be greater than a 3 letter word.
Here’s an example array:
// every 3 values of this array have been given extra space for readability only charArr = [ '--.', '..', '-.', '--..', '.', '-.', '--.', '..', '--.', '--', '...', '--.' ]
An example solution:
//every 3 values lengths are added together, sum is added to new array result = [ 7, 7, 8, 8 ]
Thanks in advance.