Skip to content

Instantly share code, notes, and snippets.

@ilpaijin
Created October 17, 2013 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilpaijin/7022193 to your computer and use it in GitHub Desktop.
Save ilpaijin/7022193 to your computer and use it in GitHub Desktop.
sort js
var str = 'ciao,zio,america,baby';
var arr = [1976,3,0,7,11];
function assorrt(d)
{
d = typeof d == 'string' ? d.split(',') : d;
for(i=0; i < d.length; i++)
{
if(typeof d[i+1] !== 'undefined')
{
if(d[i] > d[i+1])
{
var old_i = d[i+1];
d[i+1] = d[i];
d[i] = old_i;
assorrt(d);
}
}
}
return d;
}
console.info(assorrt(str));
console.info(assorrt(arr));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment