Sorting Data javascript and C#

From : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#examples


Array 


const array1 = ["Gorilla:500","Xsparrow:300","TimeRose:100"];

array1.sort((a,b) => {

  var a1 = a.split(":");

  var b1 = b.split(":");

  return parseInt(a1[1]) - parseInt(b1[1]);

});

console.log(array1);

//Asc

const array2 = ["z","B","C"];

array2.sort();

console.log(array2);

//Desc

const array3 = ["z","B","C"];

array3.sort((a,b)=>{

return b-a;

});


//Desc Anka

const array4 = [1,70,3];

array4.sort((a,b)=>{

return b-a;

});

console.log(array4);


//Asc Anka

const array5 = [1,70,3];

array5.sort((a,b)=>{

return a-b;

});

console.log(array5);


===================================



Sorting data in c#

Key : c# sort list based on another list

https://stackoverflow.com/questions/15275269/sort-a-list-from-another-list-ids


This Code For Controller


var ranking = new List<int>() { 19, 27, 26, 20, 22, 11, 8, 5, 6, 7, 21, 14, 28, 12, 25, 1, 17, 24, 23, 18, 3, 16, 13 };

list = list.OrderBy(x => ranking.IndexOf(x.Id)).ToList();

===================


Sorting Data javascript and C# Sorting Data javascript and C# Reviewed by Leo on Maret 14, 2022 Rating: 5

Tidak ada komentar

About me

About Me

My name is Joanne Doe, a lifestyle photographer and blogger currently living in Osaka, Japan. I write my thoughts and travel stories inside this blog.