Last active
August 31, 2017 17:25
-
-
Save vtemian/d7488d413309ec4b3563cf2c490095fc to your computer and use it in GitHub Desktop.
Functional
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sum_squared_array(a): | |
for index in range(len(a)): | |
a[index] = a[index] * a[index] | |
for index in range(len(a)): | |
total_not_functional += a[index] | |
total_not_functional = 0 | |
sum_squared_array([1, 2, 3, 4]) | |
total_function = reduce(lambda element, collector: collector + element, | |
map(lambda x: x ** 2, [1, 2, 3, 4]), 0) | |
total_function_simple = sum(map(lambda x: x ** 2, [1, 2, 3, 4])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment