how does this simple little javascript code work?

Asked

Viewed 18 times

0

The statement is:

Develop a function that takes two non-negative integers (greater or equal to zero) and multiply them. But do not use the multiplication operator.

Code:

function multiplicar(numero, multiplicador) {
    if (numero === 0 || multiplicador === 0) return 0
    return multiplicador === 1 ? numero : numero + multiplicar(numero, multiplicador - 1)
}

Não estou entendendo o código a partir do `:` O que é isso?

console.log(multiplicar(2, 5))
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.