We have a list of integers: [1,4,5,6,6,7,9] .
The idea is to generate a list with the same length and sum up to the current element of the type: [1,5,10,16,22,29,38] .
In the Java world, it will look like this:
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 that there are more elegant and effective solutions. My question is: how to do something like this in Scala in a more efficient way?
thanks!
source share