幸福的数字由以下过程定义:
从任何正整数开始,将数字替换为其数字的平方和,并重复该过程直到数字等于1(它将保持不变),或者它在一个不包括1的循环中无休止地循环。这些数字这个过程在1结束的是幸福的数字,而那些不以1结尾的数字是不愉快的数字。
实现一个函数,如果数字是满意的,则返回true,否则返回false。
happy
是一种功能。
testString: 'assert(typeof happy === "function", "happy
is a function.");'
- text: happy(1)
应该返回一个布尔值。
testString: 'assert(typeof happy(1) === "boolean", "happy(1)
should return a boolean.");'
- text: happy(1)
应该回归真实。
testString: 'assert(happy(1), "happy(1)
should return true.");'
- text: happy(2)
应该返回虚假。
testString: 'assert(!happy(2), "happy(2)
should return false.");'
- text: happy(7)
应该回归真实。
testString: 'assert(happy(7), "happy(7)
should return true.");'
- text: happy(10)
应该回归真实。
testString: 'assert(happy(10), "happy(10)
should return true.");'
- text: happy(13)
应该回归真实。
testString: 'assert(happy(13), "happy(13)
should return true.");'
- text: happy(19)
应该回归真实。
testString: 'assert(happy(19), "happy(19)
should return true.");'
- text: happy(23)
应该回归真实。
testString: 'assert(happy(23), "happy(23)
should return true.");'
- text: happy(28)
应该回归真实。
testString: 'assert(happy(28), "happy(28)
should return true.");'
- text: happy(31)
应该回归真实。
testString: 'assert(happy(31), "happy(31)
should return true.");'
- text: happy(32)
应该回归真实:
testString: 'assert(happy(32), "happy(32)
should return true:.");'
- text: happy(33)
应该返回虚假。
testString: 'assert(!happy(33), "happy(33)
should return false.");'
```