I am trying to create a simple function that finds the smallest two integers in a given array. New to typescript but good with Javascript, I am wondering why would typescript complains about adding two numbers:
const array: Number[] = [
2, 3, 4, 2, 4, 3, 5, 2, 5, 91, 2, 4, 32, 43, 3, 5, 3435,
];
const twoSmallest = (array: Number[]): Number[] => {
if (array.length < 2) return array;
const maxSum = array.reduce((acc: Number, curr: Number):Number => {
return curr + acc;
}, 0);
for (let i = 0; i < array.length; i++) {
//About to add my rest of the code here
}
};
console.log('Result = ', twoSmallest(array));