I prefered to return an array of objects containing all the part of the multiplication, and let the developer-user of the function choose how to format the output, that way it makes it an O(n) solution.
"use strict";constprintMultiplicationTable=(limit,number,callback,...parameters)=>{if(0!==parameters.length){thrownewReferenceError("too much parameters");}if("number"!==typeoflimit){thrownewTypeError("first argument expected to be a number");}if(!Number.isInteger(limit)){thrownewTypeError("first argument expected to be an integer");}if(1>limit){thrownewRangeError("first argument expected to be greater than zero");}if("number"!==typeofnumber){thrownewTypeError("second argument expected to be a number");}if(!Number.isInteger(number)){thrownewTypeError("second argument expected to be an integer");}if(1>number){thrownewRangeError("second argument expected to be greater than zero");}if("function"!==typeofcallback){thrownewTypeError("third argument expected to be a function");}for(letindex=0;index<limit;index++){constcurrent=index+1;if(1!==callback.length){thrownewError("third argument expect to be a function receiving only one argument");}callback({operand1:number,operand2:current,result:number*current});}}printMultiplicationTable(10,7,({operand1,operand2,result})=>{console.log(`${operand1} * ${operand2} = ${result}`);});// 7 * 1 = 7// 7 * 2 = 14// 7 * 3 = 21// 7 * 4 = 28// 7 * 5 = 35// 7 * 6 = 42// 7 * 7 = 49// 7 * 8 = 56// 7 * 9 = 63// 7 * 10 = 70
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I prefered to return an array of objects containing all the part of the multiplication, and let the developer-user of the function choose how to format the output, that way it makes it an
O(n)
solution.