Skip to content

Instantly share code, notes, and snippets.

@Arieg419
Last active November 27, 2017 07:44
Show Gist options
  • Save Arieg419/f09374c78e43885c00c9edca61e1d261 to your computer and use it in GitHub Desktop.
Save Arieg419/f09374c78e43885c00c9edca61e1d261 to your computer and use it in GitHub Desktop.
Examples of imperative code
// 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