Your task, is to create NxN multiplication table, of size provided in parameter.
for example, when given size is 3:
1 2 3
2 4 6
3 6 9
for given example, the return value should be: [[1,2,3],[2,4,6],[3,6,9]]
multiplicationTable = function(size) {
let result = [];
for (let i = 1; i <= size; i++) {
let pushedArr = [];
for (let m = 1; m <= size; m++) {
pushedArr.push(m * i);
}
result.push(pushedArr);
}
return result;
}
multiplicationTable = function(size) {
var result = [];
for (var i = 0; i < size; i++) {
result[i] = [];
for(var j = 0; j < size; j++) {
result[i][j] = (i + 1) * (j + 1);
}
}
return result
}
multiplicationTable = function(size) {
return Array.apply(null, new Array(size)).map(function(val, i) {
return Array.apply(null, new Array(size)).map(function(val, j) {
return (i+1) * (j+1);
});
});
}
func.apply(thisArg, [argsArray])
The value of this provided for the call to func.
An array-like object, specifying the arguments with which func should be called, or null or undefined if no arguments should be provided to the function.
The result of calling the function with the specified this value and arguments.
const array = ['a', 'b'];
const elements = [0, 1, 2];
array.push.apply(array, elements);
console.info(array); // ["a", "b", 0, 1, 2]
// min/max number in an array
const numbers = [5, 6, 2, 3, 7];
// using Math.min/Math.max apply
let max = Math.max.apply(null, numbers);
// This about equal to Math.max(numbers[0], ...)
// or Math.max(5, 6, ...)
let min = Math.min.apply(null, numbers);
source: mdn web docs