Skip to content

Instantly share code, notes, and snippets.

@sadeghipour
Forked from ugurozpinar/turkce_siralama.js
Last active June 2, 2021 11:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sadeghipour/41cc6853d604e152250a0b64e3185747 to your computer and use it in GitHub Desktop.
Javascript object array Turkish sorting. Türkçe Sıralama
var arr = [{id:3,title:"Ali"},{id:3,title:"Veli"},{id:3,title:"Vehbi"}];
arr.sort(turkcesiralama);
function turkcesiralama(a, b,aProp="title",bProp="title"){
var atitle = a[aProp];
var btitle = b[bProp];
var alfabe = "AaBbCcÇçDdEeFfGgĞğHhIıİiJjKkLlMmNnOoÖöPpQqRrSsŞşTtUuÜüVvWwXxYyZz0123456789";
if (atitle.length === 0 || btitle.length === 0) {
return atitle.length - btitle.length;
}
for(var i=0;i<atitle.length && i<btitle.length;i++){
var ai = alfabe.indexOf(atitle[i]);
var bi = alfabe.indexOf(btitle[i]);
if (ai !== bi) {
return ai - bi;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment