js计算单词价格
499以下 价格是569.85
500-999 价格是884.25
1000-1499 价格是1198.65
以此类推
封顶是40000字,超过4万个单词就不用计算价格了,4万以内输入任意单词个数返回相应的价格
function getPrice (num) {
if (num > 40000) return 999999999
return parseInt(num / 500) * 314.4 + 569.85
}
console.log('0==', getPrice(0))
console.log('400==', getPrice(400))
console.log('499==', getPrice(499))
console.log('500==', getPrice(500))
console.log('600==', getPrice(600))
console.log('999==', getPrice(999))
console.log('1000==', getPrice(1000))
console.log('1200==', getPrice(1200))
console.log('1499==', getPrice(1499))
基础价569.85,超过500字每多500加314.4,超过40000返回Infinity,非法输入返回0,允许输入字符串(含科学计数法)
function getPrice(num) {
let n = Number(num);
if (n > 40000) return Infinity;
if (!n || n < 0) return 0;
return parseInt(n / 500) * 314.4 + 569.85;
}
js计算单词价格
499以下 价格是569.85
500-999 价格是884.25
1000-1499 价格是1198.65
以此类推
根据你这个计算,就是按你这个规律是,单词个数除以500的商*314.4+569.85,就是根据输入单词个数得到单词价格
也就是 (str.length/500)*314.4+569.85
代码可以如下:
if(str.length<=40000){
return (str.length/500)*314.4+569.85
}else{
return (40000/500)*314.4+569.85
}