Files
Methodologies_de_tests_et_t…/src/exercises/multiplyArrays2/index.ts
2024-04-18 09:43:42 +02:00

11 lines
382 B
TypeScript

export function multiplyArrays(arr1: number[], arr2: number[]): number[] {
const isSameLength = arr1.length === arr2.length;
if (!isSameLength) throw new Error("Arrays must be the same length");
const isOneEmpty = arr1.length === 0 || arr2.length === 0;
if (isOneEmpty) throw new Error("Arrays must not be empty");
return arr1.map((num, index) => num * arr2[index]);
}