Skip to content

Instantly share code, notes, and snippets.

@galvez
Created April 4, 2021 01:24
Show Gist options
  • Save galvez/e2196fc6b95213d19f306b5a17e49ada to your computer and use it in GitHub Desktop.
Save galvez/e2196fc6b95213d19f306b5a17e49ada to your computer and use it in GitHub Desktop.
const x = [
'header-c',
'value',
'header-a',
'value',
'header-b',
'value'
]
function sort1D (arr) {
let i = arr.length
while (i -= 2) {
if (arr[i - 2] > arr[i]) {
arr.push(...arr.splice(i - 2, 2))
}
}
return arr
}
console.log(sort1D(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment