荣耀 8.14
    image.png

    1. const hmlsort = function (str) {
    2. const high = ['b', 'd', 'f', 'h', 'k', 'l'];
    3. const middle = ['a', 'c', 'e', 'i', 'm', 'n', 'o', 'r', 's', 't', 'u', 'v', 'w', 'x', 'z']
    4. const low = ['g', 'j', 'p', 'q', 'y']
    5. let strArr = str.split('');
    6. let hig = [], mid = [], lo = [];
    7. let len = strArr.length;
    8. for (let i = 0; i < len; i++) {
    9. if (high.includes(strArr[i])) {
    10. hig.push(strArr[i]);
    11. } else if (middle.includes(strArr[i])) {
    12. mid.push(strArr[i])
    13. }
    14. else {
    15. lo.push(strArr[i])
    16. }
    17. }
    18. console.log(hig.length == 0 ? null : hig.sort().join(''));
    19. console.log(mid.length == 0 ? null : mid.sort().join(''));
    20. console.log(lo.length == 0 ? null : lo.sort().join(''));
    21. }
    22. hmlsort('cvjjap');

    2021.8.21
    有赞

    69f34f1a7ad5d713af2af9b7b2e61f6.jpg

    1. function formatPrice(price) {
    2. const input = price.split('')
    3. const len = input.length
    4. let mat = ''
    5. let res = ''
    6. if(len < 5) {
    7. mat = '元'
    8. if(len<4) res=price+mat
    9. else {
    10. res = price.slice(0,1)+','+price.slice(1)+mat
    11. }
    12. }
    13. if(len >= 5 && len < 9) {
    14. mat = '万元'
    15. price = Number(price.slice(0,len-4)+'.'+price.slice(len-4,len)).toFixed(2)
    16. if(len < 8) {
    17. res = price+mat
    18. } else {
    19. res = price.slice(0,1)+','+price.slice(1)+mat
    20. }
    21. }
    22. if(len>=9) {
    23. mat = '亿元'
    24. price = Number(price.slice(0,len-8)+'.'+price.slice(len-8)).toFixed(2)
    25. if(len<11) {
    26. res = price+mat
    27. } else {
    28. let leftLen = len - 8
    29. while(leftLen > 3) {
    30. price = price.slice(0,leftLen-3)+','+price.slice(leftLen-3)
    31. leftLen -= 3
    32. res = price+mat
    33. }
    34. }
    35. }
    36. return res
    37. }
    38. console.log(formatPrice('12345678'))