3 ms·
sum = (1 to 100).map(x => x * x).reduce {case (x, y) => x + y } sum = 0 for i in 1..100 { sum += i * i } I personally find the second one easier to unders
by amedvednikov 7y ago
sum = (1 to 100).map(x => x * x).reduce {case (x, y) => x + y }
sum = 0
for i in 1..100 { sum += i * i }
I personally find the second one easier to understand. Performance is much better unless the compiler does some magic to convert the first version to the second one.
Adding more logic to the loop also doesn't make the code more complex.