Created
October 6, 2022 17:14
-
-
Save iliacodes/1f8f0c5b6de783e484e426a790e37afa to your computer and use it in GitHub Desktop.
Kata 1 - Sum the Largest Numbers Assignment
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
function sumLargestNumbers(data) { | |
var a = data[0]; | |
var b = data[0]; | |
for(i = 1; i < data.length; i++) { | |
if (data[i] > a) { | |
b = a; | |
a = data[i]; | |
} else if (data[i] > b) { | |
b = data[i]; | |
} | |
} | |
return a+b; | |
} | |
console.log(sumLargestNumbers([1, 10])); | |
console.log(sumLargestNumbers([1, 2, 3])); | |
console.log(sumLargestNumbers([10, 4, 34, 6, 92, 2])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kata 1 lab for LHL