码迷,mamicode.com
首页 > 编程语言 > 详细

排序并获取index的顺序

时间:2014-10-21 13:36:59      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:io   ar   for   on   cti   type   return   function   c   

//排序并获取index的顺序:4,7,2,9-->9,7,4,2-->4,2,1,3
Array.prototype.getIndex=function(){
  var orderLength = this.length;
  var temp,tp;
  var c=[];
  for(var l=0;l<orderLength;l++){
  c[l]=l;
  }
  for(var u=0;u<orderLength;u++){
    for (var v=0;v<orderLength-u-1;v++){
      if(this[v]<this[v+1]){
        temp=this[v];
        this[v]=this[v+1];
        this[v+1]=temp;
        tp=c[v];
        c[v]=c[v+1];
        c[v+1]=tp;
      }
    }
  }
  return c;
}

排序并获取index的顺序

标签:io   ar   for   on   cti   type   return   function   c   

原文地址:http://www.cnblogs.com/cdwp8/p/4040029.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!