DEV Community

Cesar Del rio
Cesar Del rio

Posted on • Updated on


#30 - Multiplication table CodeWars Kata (6 kyu)


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]]

My solution:

multiplicationTable = function(size) {
  let r = []
  for(let i = 1; i<=size; i++){
    let x = []
    for(let j = 1; j<=size; j++){
  return r

Enter fullscreen mode Exit fullscreen mode


First I declarated the variable "r" with an empty array, wich will contain the last result.

After that I used a for loop to iterate the array, and for every iteration I did a "x" variable with an empty array and another for loop, inside of this loop I will iterate through the size value, and in every iteration I will push to x the result of the multiplication of i by j, that way for example if I'm in the first value of the array in the first for loop, I will always be equal to 1 in the second loop, but j will be changing in every iteration, so I can get [1*1,1*2,1*3] in the x array, and at the end I just returned r

What do you think about this solution? 👇🤔

My Github
My twitter
Solve this Kata

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.