javascript node环境下:

看到有用冒泡排序的方法解决的,这里提供另一种思路,性能比较没有测(心情不好,别问我为什么)


var rl = require('readline').createInterface(process.stdin, process.stdout)
rl.on('line', function (line) {
    var data=line.split(",");
    var arr = data.map(function(item,index){
        return {'key':index,'value':parseInt(item)}
    }) 
    var sortArr = arr.sort(function(a,b){
        return b.value - a.value
    }).map(function(item){
        return item.key
    })
    console.log(sortArr.join(','));
})

 

提供一组测试用例:

数组由大到小排序并返回排序后的下标

 

相关文章:

  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2021-12-18
  • 2022-01-09
  • 2021-11-29
  • 2021-11-14
猜你喜欢
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2022-02-11
  • 2021-11-23
  • 2022-02-11
  • 2021-10-07
相关资源
相似解决方案