Code I did for Codewars...
One of the problems I did on Codewars today was to add the two smallest numbers in an array. The array was [19, 5, 42, 2, 77]. It has been literally months since I did this so my mind was confused. Instead of googling and typing the answer down, I wa...
joemcgee4151986.hashnode.dev1 min read
Tobbe Lundberg
Fullstack developer with a focus on the technical frontend
I saw this, and had to try it myself
Here's another way to do it. Probably worse than your solution. But I wanted to make it a chain of function calls
function sumTwoSmallestNumbers(numbers) { return (numbers.sort((a, b) => a - b)) .slice(0, 2) .reduce((prev, cur) => prev + cur) }