Last active
March 1, 2024 17:31
-
-
Save cplpearce/b4b95bc5679b6b885399caea04d137b5 to your computer and use it in GitHub Desktop.
Kata 1 - Sum the Largest Numbers
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
const sumLargestNumbers = function(data) { | |
let numOne = {index : 0, value : 0}; | |
let numTwo = 0; | |
for (let [i, num] of data.entries()) { | |
num > numOne.value && (numOne.index = i) && (numOne.value = num); | |
} | |
data.splice(numOne.index, 1); | |
for (let num of data) { | |
num > numTwo && (numTwo = num); | |
} | |
return numOne.value + numTwo; | |
}; | |
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