MST
星途 面试题库

面试题:TypeScript 中剩余参数与数组 map 方法结合应用

请编写一个 TypeScript 函数,它接受一个字符串作为第一个参数,然后接受任意数量的数字作为剩余参数。函数需要将每个数字与字符串的长度相乘,最后返回结果数组。例如,调用函数 `combine('hello', 2, 3)`,应返回 `[10, 15]`。
24.8万 热度难度
前端开发TypeScript

知识考点

AI 面试

面试题答案

一键面试
function combine(str: string, ...nums: number[]): number[] {
    return nums.map(num => num * str.length);
}