编辑代码

// 冒泡排序,从小到大
// const arr = [2,3,4,5,6,1,5]
// for (let i = 0 ; i< arr.length ; i++){
//     for (let j = i+1; j<arr.length; j++){
//         if(arr[i]>arr[j]){
//             const temp = arr[i]
//             arr[i] = arr[j]
//             arr[j] = temp
//         }
//     }
// }
// console.log(arr)
// 写成函数 从大到小
//  const arr  = [1,4,8,3,5,7,]
//  function mp(arr){
//      for (let i = 0 ; i<arr.length; i++){
//          for (let j = i+1; j< arr.length ; j++){
//              if(arr[i] < arr[j]){
//                 temp=   arr[i]
//                 arr[i] = arr[j]
//                 arr[j] = temp

//              }
//          }
//      }
//      return arr
//  }
//  console.log(mp(arr))

// 选择排序 从大到小
// const arr = [2,5,7,9,3,1,8]
// for (let i = 0; i<arr.length-1; i++){
//     var max = i
//     for ( let j = i+1; j<arr.length ;j++){
//         if(arr[j] > arr [max]){
//             max = j
//         }
//     }
//     // console.log(max)
//     const temp = arr[i]
//     arr[i] = arr[max]
//     arr[max] =temp
// }
// console.log(arr)

// const arr = [5,9,7,3,4,8]
// function xz (arr){
//     for (let i = 0; i<arr.length-1 ; i++ ){
//         var max  = i
//         for( let j =i+1 ; j<arr.length; j++){
//             if(arr[max] < arr[j]){
//                 max = j
//             }
//         }
//         const temp = arr[i]
//         arr[i] = arr[max]
//         arr[max] = temp
//     }
//     return arr
// }
// console.log(xz(arr))

// 一个字符串里面某个字母出现的次数

// str.charAt
// const str1 = 'safs'
// const res1= str1.charAt(1)
// console.log(res1)

// obj[]
// const obj2 ={a:1,b:2}
// obj2.d = 3
// console.log(obj2['a'])
// console.log(obj2['c'])
// console.log(obj2['d'])


// const str ='asdfsdfshjgfffdf'
// const obj = {}
// for ( let i = 0;i<str.length;i++){
//     if(!obj[str.charAt(i)]){
//         obj[str.charAt(i)] = 1
//     }else{
//         obj[str.charAt(i)]++
//     }
// }
// console.log(obj)
// let word = ''
// let count = 0
// for ( var j in obj ){
//     // console.log(j)
//     // console.log(obj[j])
//     if(obj[j] > count){
//         word = j
//         count  = obj[j]
//     }
// }
// console.log(word,count)

// 数组中元素出现的次数
// const arr = ['aa','a','a','a','ssd','as']
// const res =arr.reduce((pre,cur) =>{
//     if(cur in pre){
//         pre[cur]++
//     }else{
//         pre[cur] =1
//     }
//     return pre
// },{})
// console.log(res)


// // 转RMB
const str = 123456234
// console.log(typeof str)
// console.log(str.toString())
const res = str.toString().split('').reverse()
// console.log(typeof res)
const res1 = []
for (let i = 0; i < res.length; i++) {
    if (i % 3 === 0 && i !=0){
       res1.push(',')
    }else{
        res1.push(res[i])
    }
}
const res2 = res1.reverse().join('')
console.log(res2)