Complete the code to declare a function that adds two numbers and returns a number.
function add(a: number, b: number): [1] { return a + b; }
The function returns a number because it adds two numbers.
Complete the code to declare a function that takes a string and returns its length as a number.
function getLength(text: string): [1] { return text.length; }
The length property of a string is a number.
Fix the error in the function by specifying the correct return type.
function isEven(num: number): [1] { return num % 2 === 0; }
The function returns true or false, so the return type is boolean.
Fill both blanks to declare a function that takes an array of numbers and returns the sum as a number.
function sumArray(arr: [1]): [2] { return arr.reduce((acc, val) => acc + val, 0); }
The function takes an array of numbers (number[]) and returns a number which is the sum.
Fill all three blanks to declare a function that takes a string and a number, and returns a string repeated that many times.
function repeatText(text: [1], times: [2]): [3] { return text.repeat(times); }
The function takes a string and a number, and returns a string repeated multiple times.