We have a list of integers like: [1,4,5,6,6,7,9]
.
The idea is to generate a list with the same length and sums up till the current element like: [1,5,10,16,22,29,38]
.
In the Java world it would look like:
int sum = 0;
int[] table = {1,4,5,6,6,7,9}
int[] res = new int[table.length]
for(int i=0; i<table.length; i++) {
sum += table[i]
res[i] = sum
}
I know there exist more elegant and efficient solutions. My question is how to do something like this in Scala in more fuctional way?
Thx!