Un número feliz se define mediante el siguiente proceso:
Comenzando con cualquier entero positivo, reemplaza el número por la suma de los cuadrados de sus dígitos y repite el proceso hasta que el número sea igual a 1 (donde permanecerá), o se repite sin cesar en un ciclo que no incluye 1. Esos números por lo que este proceso termina en 1 son números felices, mientras que aquellos que no terminan en 1 son números infelices.
Implemente una función que devuelva verdadero si el número es feliz o falso si no lo es.
happy
es una función.
testString: 'assert(typeof happy === "function", "happy
is a function.");'
- text: happy(1)
debe devolver un booleano.
testString: 'assert(typeof happy(1) === "boolean", "happy(1)
should return a boolean.");'
- text: happy(1)
debe devolver verdadero.
testString: 'assert(happy(1), "happy(1)
should return true.");'
- text: happy(2)
debe devolver falso.
testString: 'assert(!happy(2), "happy(2)
should return false.");'
- text: happy(7)
debe devolver verdadero.
testString: 'assert(happy(7), "happy(7)
should return true.");'
- text: happy(10)
debe devolver verdadero.
testString: 'assert(happy(10), "happy(10)
should return true.");'
- text: happy(13)
debe devolver el verdadero.
testString: 'assert(happy(13), "happy(13)
should return true.");'
- text: happy(19)
debe devolver el verdadero.
testString: 'assert(happy(19), "happy(19)
should return true.");'
- text: happy(23)
debe devolver verdadero.
testString: 'assert(happy(23), "happy(23)
should return true.");'
- text: happy(28)
debe devolver verdadero.
testString: 'assert(happy(28), "happy(28)
should return true.");'
- text: happy(31)
debe devolver verdadero.
testString: 'assert(happy(31), "happy(31)
should return true.");'
- text: 'happy(32)
debe devolver verdadero :.'
testString: 'assert(happy(32), "happy(32)
should return true:.");'
- text: happy(33)
debe devolver falso.
testString: 'assert(!happy(33), "happy(33)
should return false.");'
```