Skip to content

Instantly share code, notes, and snippets.

@Echooff3
Created July 6, 2017 20:55
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 Echooff3/dac42d23e07a6e1ea5c9069e2c68b61c to your computer and use it in GitHub Desktop.
Save Echooff3/dac42d23e07a6e1ea5c9069e2c68b61c to your computer and use it in GitHub Desktop.
XOR Sort
let x = Array.from(new Array(10), () => {return (Math.random() * (20 - 1) + 1) | 0})
const _xorSort = (x) => {
for( i = 0; i < x.length; i++) {
for( j = 0; j < x.length; j++) {
if(x[i] < x[j]) {
x[i] = x[i] ^ x[j]
x[j] = x[i] ^ x[j]
x[i] = x[i] ^ x[j]
}
}
}
return x
}
console.log(x)
_xorSort(x)
console.log(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment