Last active
November 27, 2017 07:44
-
-
Save Arieg419/f09374c78e43885c00c9edca61e1d261 to your computer and use it in GitHub Desktop.
Examples of imperative code
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
// triple the value of every element in a given array | |
const triple = (arr) => { | |
let results = [] | |
for (let i = 0; i < arr.length; i++){ | |
results.push(arr[i] * 3) | |
} | |
return results | |
} | |
// sum all the elements in a given array | |
const sum = (arr) => { | |
let result = 0 | |
for (let i = 0; i < arr.length; i++){ | |
result += arr[i] | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment