jaredcb
New Coder
I'm scratching my head over this one. Not sure if I'm asking this question wrong, but I'm trying to reach out where I can hopefully find someone who knows what I can try. I tried asking this on another forum, and they didn't like that I didn't have any example of failed code yet, so they wouldn't help. The trouble is, I don't even know what code I would try here, or where to begin. So I'm kinda stuck. Here's the problem:
I have two arrays, with the same lengths, which reference each other, and I need to use both arrays to create a new third array. The first array contains names, the second contains numbers assigned to each name. The Name Array has several instances of repeating names (and some that are listed only once).
So what I am trying to do is build a new array that uses this logic: Take the sum of any group of repeating names, as they appear in sequence, and assign the sum to its own element in the new array, then move on to the next.
For example:
So Jack is 2+3+7, Betty is 3, Tim is 5, John is 6+1, and Jack is 4+5.
Then the new array should look like this:
But I can't seem to figure out how to achieve this. Any ideas?
Again, if I'm not asking this correctly, I apologize. I'm just pulling my hair out a bit with this one. Any insight is appreciated.
I have two arrays, with the same lengths, which reference each other, and I need to use both arrays to create a new third array. The first array contains names, the second contains numbers assigned to each name. The Name Array has several instances of repeating names (and some that are listed only once).
So what I am trying to do is build a new array that uses this logic: Take the sum of any group of repeating names, as they appear in sequence, and assign the sum to its own element in the new array, then move on to the next.
For example:
Code:
nameArray = [Jack, Jack, Jack, Betty, Tim, John, John, Jack, Jack]
numberArray = [2, 3, 7, 3, 5, 6, 1, 4, 5]
So Jack is 2+3+7, Betty is 3, Tim is 5, John is 6+1, and Jack is 4+5.
Then the new array should look like this:
Code:
newArray = [12, 3, 5, 7, 9]
But I can't seem to figure out how to achieve this. Any ideas?
Again, if I'm not asking this correctly, I apologize. I'm just pulling my hair out a bit with this one. Any insight is appreciated.