Skip to content

Instantly share code, notes, and snippets.

@ShigekiKarita
Last active August 29, 2015 14:04
Show Gist options
  • Save ShigekiKarita/be25933b1debb185a3c2 to your computer and use it in GitHub Desktop.
Save ShigekiKarita/be25933b1debb185a3c2 to your computer and use it in GitHub Desktop.
JavaScriptのリスト内包表記が括弧悪い
// for firefox31
const quicksort = (array) =>
{
if (array.length == 0) return [];
const head = array[0];
const rest = array.slice(1);
const small = [i for each (i in rest) if (head >= i)]; //rest.filter(a => head >= a);
const large = [i for each (i in rest) if (head < i)]; //rest.filter(a => head < a);
return [].concat(quicksort(small), head, quicksort(large));
};
quicksort([2,5,3,2,-1]); // Array [ -1, 2, 2, 3, 5 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment