Um número feliz é definido pelo seguinte processo:
Começando com qualquer número inteiro positivo, substitua o número pela soma dos quadrados de seus dígitos e repita o processo até que o número seja igual a 1 (onde permanecerá), ou faça um loop infinitamente em um ciclo que não inclua 1. Esses números para os quais este processo termina em 1 são números felizes, enquanto aqueles que não terminam em 1 são números infelizes.
Implemente uma função que retorne true se o número for feliz ou false, se não for.
happy
é uma função.
testString: 'assert(typeof happy === "function", "happy
is a function.");'
- text: happy(1)
deve retornar um booleano.
testString: 'assert(typeof happy(1) === "boolean", "happy(1)
should return a boolean.");'
- text: happy(1)
deve retornar verdadeiro.
testString: 'assert(happy(1), "happy(1)
should return true.");'
- text: happy(2)
deve retornar falso.
testString: 'assert(!happy(2), "happy(2)
should return false.");'
- text: happy(7)
deve retornar verdadeiro.
testString: 'assert(happy(7), "happy(7)
should return true.");'
- text: happy(10)
deve retornar verdadeiro.
testString: 'assert(happy(10), "happy(10)
should return true.");'
- text: happy(13)
deve retornar verdadeiro.
testString: 'assert(happy(13), "happy(13)
should return true.");'
- text: happy(19)
deve retornar verdadeiro.
testString: 'assert(happy(19), "happy(19)
should return true.");'
- text: happy(23)
deve retornar verdadeiro.
testString: 'assert(happy(23), "happy(23)
should return true.");'
- text: happy(28)
deve retornar verdadeiro.
testString: 'assert(happy(28), "happy(28)
should return true.");'
- text: happy(31)
deve retornar verdadeiro.
testString: 'assert(happy(31), "happy(31)
should return true.");'
- text: 'happy(32)
deve retornar verdadeiro:'
testString: 'assert(happy(32), "happy(32)
should return true:.");'
- text: happy(33)
deve retornar falso.
testString: 'assert(!happy(33), "happy(33)
should return false.");'
```