Scala: A sum of the squares algorithm using map/sum and foldLeft
Briefly

Using foldLeft instead of map/sum may offer more efficiency as it walks through each value in the Map, creating a simple sum of the squares without requiring an intermediate collection.
In summary, this code shows a few different ways to create a sum of the squares algorithm in Scala. I'm sure there are many more ways to do this, but these are the first two approaches that came to mind. Which reminds me of a Viktor Klang proverb: If you only have one solution, it may well be the worst.
Read at alvinalexander.com
[
add
]
[
|
|
]