“Urutkan fungsi” Kode Jawaban

urutkan urutan menurun c stl

sort(arr, arr + n, greater<int>())
Gentle Gibbon

JavaScript orderby

var items = [
  { name: 'Edward', value: 21 },
  { name: 'Sharpe', value: 37 },
  { name: 'And', value: 45 },
  { name: 'The', value: -12 },
  { name: 'Magnetic', value: 13 },
  { name: 'Zeros', value: 37 }
];

// sort by value
items.sort(function (a, b) {
  return a.value - b.value;
});

// sort by name
items.sort(function(a, b) {
  var nameA = a.name.toUpperCase(); // ignore upper and lowercase
  var nameB = b.name.toUpperCase(); // ignore upper and lowercase
  if (nameA < nameB) {
    return -1;
  }
  if (nameA > nameB) {
    return 1;
  }

  // names must be equal
  return 0;
});
Clever Crocodile

JavaScript Sort Object

var maxSpeed = {
    car: 300, 
    bike: 60, 
    motorbike: 200, 
    airplane: 1000,
    helicopter: 400, 
    rocket: 28800
};
var sortable = [];
for (var vehicle in maxSpeed) {
    sortable.push([vehicle, maxSpeed[vehicle]]);
}

sortable.sort(function(a, b) {
    return a[1] - b[1];
});

//[["bike", 60], ["motorbike", 200], ["car", 300],
//["helicopter", 400], ["airplane", 1000], ["rocket", 28800]]
Ankur

Urutkan array menurut array pertama JS

itemsArray.sort(function(a, b){  
  return sortingArr.indexOf(a) - sortingArr.indexOf(b);
});
Embarrassed Echidna

jenis javascript

homes.sort(function(a, b) {
    return parseFloat(a.price) - parseFloat(b.price);
});
Fancy Fox

Urutkan fungsi

a=[2,2,4,1]
b=a
a.sort()
// a now points to object [1,2,2,4]
c=sorted(b)
//c and b also points to [1,2,2,4] 
// sort works on array only but sorted also on strings but return array of char
s="sjndk"
print(sorted(s))
// prints ['d', 'j', 'k', 'n', 's']
// sorted also works on list of strings(sorts alphabetically)
ap_Cooperative_dev

Jawaban yang mirip dengan “Urutkan fungsi”

Pertanyaan yang mirip dengan “Urutkan fungsi”

Lebih banyak jawaban terkait untuk “Urutkan fungsi” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya