Создать функцию с двумя аргументами, первый - множитель, второй - длина массива
Create a function with two arguments that will return an array of the first (n) multiples of (x).
Assume both the given number and the number of times to count will be positive numbers greater than 0.
Return the results as an array
Examples:
countBy(1,10) === [1,2,3,4,5,6,7,8,9,10] countBy(2,5) === [2,4,6,8,10]
В примере указана проблема. Нужна функция, которая будет возвращать массив, от 1 до 10 (в первом случае) единица - множитель, 10 - длина массива. Во втором случае: 2 - множитель, 5 - длина массива. Если, например, указать countBy(3,3), то вернуться должен массив вида [3,6,9]
function countBy(x, n) {
let z = [];
}
return z;
function countBy(x, n) {
let z = [];
let arr = Array(n).fill().map((e, i) => i + 1)
z = arr.map((el) => el*x)
return z;
}
Решил самостоятельно.
Ответы (1 шт):
Автор решения: UModeL
→ Ссылка
Учебное задание начального уровня. Серьёзная проблема заключается в лени.
function countBy(x, n) {
let z = [];
for (i = 1; i <= n; ++i) {
z.push(i * x);
}
return z;
}
console.log(countBy(1, 10));
console.log(countBy(2, 5));
console.log(countBy(3, 3));