Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
- Go
- Clojure
- Clojure
- Clojure
- C#
- Dart
- Fortran
- Groovy
- Haskell
- JS
- Java
- Java
- Java
- Pascal
- Perl
- Python
- Python
- Ruby
- Ruby
- Rust
(defn square [x] (* x x))
(def s (reduce + (map square data)))
(defn square [x] (* x x))
(def s (transduce (map square) + data))
This doesn't create any intermediate collection
(defn square [x] (* x x))
(def s (->> data (map square) (reduce +)))
s = sum( data**2 )
data may be a multidimensional array (e.g. data(:,:)).
sumOfSquares = sum . map (^2)
Because data is a keyword in Haskell, this is a function for computing the sum of squares.
sumOfSquares :: Num c => [c] -> c
sumOfSquares :: Num c => [c] -> c
s = sum(i**2 for i in data)
f = lambda x: x * x
s = sum(map(f, data))