Created
November 23, 2020 13:28
-
-
Save einarpersson/a0d3eef71db9796adbd79d9474bf3175 to your computer and use it in GitHub Desktop.
This file contains 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
// en funktion som summerar alla tal i en array | |
// låt result vara 0 | |
// för i från 0 till array.length - 1 | |
// result = result + array[i] | |
// return result | |
function sum(arr) { | |
let result = 0 | |
for (let i = 0; i < arr.length; i++) { | |
result = result + arr[i] | |
console.log('vi är i loopen och elementet har värdet ' + arr[i] + ' och result är ' + result) | |
} | |
return result | |
} | |
console.log(sum([5, 3, 7, 2])) // 15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment