1г



Программирование
+3Помогите решить задачу JavaScript
в задаче подразумевается отсутствие циклов
Задача 1
Давайте выведем на экран всю таблицу умножения. Объявите функцию printRow с одним параметром x, которая будет печатать на экран строку умножения на x. Например, если x == 1 то она напечатает 1 2 3 4 5 6 7 8 9, а если x == 2 то напечатает 2 4 6 8 10 12 14 16 18. Вызовите её 9 раз, передавая ей в качестве аргумента числа от 1 до 9.
По дате
По рейтингу
1234
function printRow(x) {
console.log([...Array(10)].map((_, i) => (i + 1) * x).join(' '));
}
[...Array(9)].forEach((_, i) => printRow(i + 1));
1234567891011
const printRow = (x) => {
const row = [1, 2, 3, 4, 5, 6, 7, 8, 9];
console.log(row.map((e) => e * x).join(' '), '\n');
};
const printTable = () => {
const column = [1, 2, 3, 4, 5, 6, 7, 8, 9];
column.map((x) => printRow(x));
};
printTable();
12345678910111213141516171819202122232425262728293031323334353637
printRow = (x)=>console.log([...Array(10)].map((_, i) => (i + 1) * x).join(' '));
(x)=>console.log([...Array(10)].map((_, i) => (i + 1) * x).join(' '))
str =[];/*фух наконец то можно использовать цыкл без него невозможно было прямо */for(i=0; i<10;i++)str.push('printRow ('+i+')')
10
console.log(str.join('\r\n'))
VM672:1 printRow (0)
printRow (1)
printRow (2)
printRow (3)
printRow (4)
printRow (5)
printRow (6)
printRow (7)
printRow (8)
printRow (9)
undefined
printRow (0)
printRow (1)
printRow (2)
printRow (3)
printRow (4)
printRow (5)
printRow (6)
printRow (7)
printRow (8)
printRow (9)
0 0 0 0 0 0 0 0 0 0
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
undefined

1234567891011121314151617181920
function printRow(x, y = 1) {
if (y > 9) return;
console.log(x * y);
printRow(x, y + 1);
}
function printTable(i = 1) {
if (i > 9) return;
console.log(`multiplication table for ${i}`);
printRow(i);
console.log('\n'); // for empty space between the tables
printTable(i + 1);
}
printTable();
function printRow(x) {
let row = "";
for (let i = 1; i <= 9; i++) {
row += x * i + " ";
}
console.log(row);
}
for (let i = 1; i <= 9; i++) {
printRow(i);
}
Больше по теме