荣耀 8.14
const hmlsort = function (str) {const high = ['b', 'd', 'f', 'h', 'k', 'l'];const middle = ['a', 'c', 'e', 'i', 'm', 'n', 'o', 'r', 's', 't', 'u', 'v', 'w', 'x', 'z']const low = ['g', 'j', 'p', 'q', 'y']let strArr = str.split('');let hig = [], mid = [], lo = [];let len = strArr.length;for (let i = 0; i < len; i++) {if (high.includes(strArr[i])) {hig.push(strArr[i]);} else if (middle.includes(strArr[i])) {mid.push(strArr[i])}else {lo.push(strArr[i])}}console.log(hig.length == 0 ? null : hig.sort().join(''));console.log(mid.length == 0 ? null : mid.sort().join(''));console.log(lo.length == 0 ? null : lo.sort().join(''));}hmlsort('cvjjap');
2021.8.21
有赞

function formatPrice(price) {const input = price.split('')const len = input.lengthlet mat = ''let res = ''if(len < 5) {mat = '元'if(len<4) res=price+matelse {res = price.slice(0,1)+','+price.slice(1)+mat}}if(len >= 5 && len < 9) {mat = '万元'price = Number(price.slice(0,len-4)+'.'+price.slice(len-4,len)).toFixed(2)if(len < 8) {res = price+mat} else {res = price.slice(0,1)+','+price.slice(1)+mat}}if(len>=9) {mat = '亿元'price = Number(price.slice(0,len-8)+'.'+price.slice(len-8)).toFixed(2)if(len<11) {res = price+mat} else {let leftLen = len - 8while(leftLen > 3) {price = price.slice(0,leftLen-3)+','+price.slice(leftLen-3)leftLen -= 3res = price+mat}}}return res}console.log(formatPrice('12345678'))
