这些是我需要用jquery做的逻辑步骤:
x是从input.value()派生的2位数字(整数);
If var x is **not** 33 or 44
Convert this 2 digit number to string;
split the string in 2 parts as number;
Add these 2 values until they reduce to single digit;
Return var x value as this value;
Else
Return var x value literally as 33 or 44 whatever is the case;
谢谢!
最佳答案
if (x != 33 && x != 44) {
while (x > 9) {
var parts = ('' + x).split('');
x = parseInt(parts[0]) + parseInt(parts[1]);
}
return x;
} else {
return x;
}
仅当输入的长度确实超过2位数时才有效,否则您需要在parts.length上的for循环中添加数字.例如.:
if (x != 33 && x != 44) {
while (x > 9) {
var parts = ('' + x).split('');
for (var x = 0,i = 0; i < parts.length; i++) {
x += parseInt(parts[i]);
}
}
return x;
} else {
return x;
}