167 views
Sum of the two smallest elements in the array
Task condition
Given an array containing at least four positive integers. The task is to output the two smallest numbers (which can then be summed).
function sumTwoMin(arr) {
return arr.sort((a, b) => a - b).slice(0, 2);
}
console.log(sumTwoMin([19, 5, 42, 2, 77]));