如何使这些 javascript 语句看起来更具可读性。可以使用函数库 ramda.js 使这段代码看起来更好吗?
var getTextSpace = function(len)
{
var tlength;
if (len >= 1 && len <= 4) {
tlength = 10;
} else if (len === 5) {
tlength = 14;
} else if (len === 6) {
tlength = 16;
} else if (len === 7) {
tlength = 18;
} else if (len >= 8 && len <= 10) {
tlength = 20;
} else if (len === 11) {
tlength = 22;
} else if (len === 12) {
tlength = 24;
} else if (len >= 13 && len <= 15) {
tlength = 26;
} else if (len === 16) {
tlength = 28;
} else if (len >= 17 && len <= 20) {
tlength = 32;
} else if (len >= 21 && len <= 34) {
tlength = tlength * 2;
} else if (len >= 35 && len <= 80) {
tlength = Math.round((len + len / 100 * 50));
}
else {
tlength = Math.round((len + len / 100 * 30));
}
return tlength;
};
先感谢您。
也许有可能做一些允许这样做的事情?
value
.between(2,20).then(20)
.between(21,22).then(0)
.greater(25).then(25))
.less(30).then(function(value) {return value * 20 )})