2.7 KiB
2.7 KiB
title | id | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
Happy numbers | 594810f028c0303b75339ad1 | 5 | 快乐的数字 |
Description
幸福的数字由以下过程定义:
从任何正整数开始,将数字替换为其数字的平方和,并重复该过程直到数字等于1(它将保持不变),或者它在一个不包括1的循环中无休止地循环。这些数字这个过程在1结束的是幸福的数字,而那些不以1结尾的数字是不愉快的数字。
实现一个函数,如果数字是满意的,则返回true,否则返回false。
Instructions
Tests
tests:
- text: <code>happy</code>是一种功能。
testString: 'assert(typeof happy === "function", "<code>happy</code> is a function.");'
- text: <code>happy(1)</code>应该返回一个布尔值。
testString: 'assert(typeof happy(1) === "boolean", "<code>happy(1)</code> should return a boolean.");'
- text: <code>happy(1)</code>应该回归真实。
testString: 'assert(happy(1), "<code>happy(1)</code> should return true.");'
- text: <code>happy(2)</code>应该返回虚假。
testString: 'assert(!happy(2), "<code>happy(2)</code> should return false.");'
- text: <code>happy(7)</code>应该回归真实。
testString: 'assert(happy(7), "<code>happy(7)</code> should return true.");'
- text: <code>happy(10)</code>应该回归真实。
testString: 'assert(happy(10), "<code>happy(10)</code> should return true.");'
- text: <code>happy(13)</code>应该回归真实。
testString: 'assert(happy(13), "<code>happy(13)</code> should return true.");'
- text: <code>happy(19)</code>应该回归真实。
testString: 'assert(happy(19), "<code>happy(19)</code> should return true.");'
- text: <code>happy(23)</code>应该回归真实。
testString: 'assert(happy(23), "<code>happy(23)</code> should return true.");'
- text: <code>happy(28)</code>应该回归真实。
testString: 'assert(happy(28), "<code>happy(28)</code> should return true.");'
- text: <code>happy(31)</code>应该回归真实。
testString: 'assert(happy(31), "<code>happy(31)</code> should return true.");'
- text: <code>happy(32)</code>应该回归真实:
testString: 'assert(happy(32), "<code>happy(32)</code> should return true:.");'
- text: <code>happy(33)</code>应该返回虚假。
testString: 'assert(!happy(33), "<code>happy(33)</code> should return false.");'
Challenge Seed
function happy (number) {
// Good luck!
}
Solution
// solution required