define a function that takes a list of numbers as an argument and returns the sum of the numbers in the list. in typescript

Here's the code to define a function that takes a list of numbers as an argument and returns the sum of the numbers in the list in typescript:

index.ts
function sumList(numbers: Array<number>): number {
  let sum = 0;
  for(let i = 0; i < numbers.length; i++) {
    sum += numbers[i];
  }
  return sum;
}
153 chars
8 lines

In this code, we define a function called sumList that takes a list of numbers as an argument. We use a for loop to iterate over each number in the list and add it to a sum variable. Finally, we return the sum variable, which represents the total sum of all the numbers in the list.

gistlibby LogSnag