JavaScript中的整洁数字
整齐的数字是数字以非降序排列的数字。
例如-
489 is a tidy number 234557 is also a tidy number 34535 is not a tidy number
我们需要编写一个JavaScript函数,该函数接受一个数字并检查其数字是否整齐。
示例
以下是代码-
const num = 234789;
const isTidy = (num, last = 10) => {
if(num){
if(num % 10 > last){
return false;
};
return isTidy(Math.floor(num / 10), (num % 10));
};
return true;
};
console.log(isTidy(num));输出结果
这将在控制台上产生以下输出-
true
热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短