const getProductOfAllOtherElements = (numbers: number[]) => {
let products : number[] = [];
for (let i = 0; i < numbers.length; i++)
{
products[i] = 1;
for (let j = 0; j < numbers.length; j++)
{
if (i != j)
{
products[i] = products[i] * numbers[j];
}
}
}
return products;
};
const printSeparator = (size: number = 64) => {
console.log(Array(size).join('-'));
};
const evaluate = (input: number[], expectedOutput: number[]) => {
const result = getProductOfAllOtherElements(input);
console.log(`Input: ${JSON.stringify(input)}`);
console.log(`ExpectedOutput: ${JSON.stringify(expectedOutput)}`);
console.log(`Result: ${JSON.stringify(result)}`);
console.log(`IsCorrect: ${JSON.stringify(result) == JSON.stringify(expectedOutput)}`);
};
printSeparator();
evaluate([3, 2, 1], [2, 3, 6]);
printSeparator();
evaluate([1, 2, 3, 4, 5], [120, 60, 40, 30, 24]);
printSeparator();
To embed this project on your website, copy the following code and paste it into your website's HTML: