Sorted by the new coming and the

2019-10-29  本文已影响0人  yilinUnique
var sortedArr = [];
function getSortedArray(obj) {
  var existIndex = -1;
  sortedArr.forEach(function(e, i) {
    if (e.id === obj.id) {
      existIndex = i;
    }
  });
  if (existIndex >= 0) {
    var a = sortedArr.slice(0, existIndex);
    a.unshift(obj);
    sortedArr = a.concat(sortedArr.slice(existIndex + 1));
  } else {
    sortedArr.unshift(obj);
  }
  return sortedArr;
}
sorted.png
上一篇 下一篇

猜你喜欢

热点阅读