Skip to content

Instantly share code, notes, and snippets.

@alicethewhale
Created December 11, 2018 16:06
Show Gist options
  • Save alicethewhale/2faa2af53dc38d7af8b3980345bdddf3 to your computer and use it in GitHub Desktop.
Save alicethewhale/2faa2af53dc38d7af8b3980345bdddf3 to your computer and use it in GitHub Desktop.
const inversionCount = array => {
return array.reduce((accumulator, current, index, array) => {
return array
.slice(index)
.filter(item => {
return item < current;
})
.map(item => {
return [current, item];
})
.concat(accumulator);
}, []).length;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment