Skip to content

Instantly share code, notes, and snippets.

@krowter
Last active March 22, 2020 04:02
Show Gist options
  • Save krowter/d9ca28329e71d0c1484a07ffca0b433b to your computer and use it in GitHub Desktop.
Save krowter/d9ca28329e71d0c1484a07ffca0b433b to your computer and use it in GitHub Desktop.
//array input
let input = [9, -1, 8, 3, -2, 9, 4, -3, 9]
//bilangan yang ingin kita pindahkan ke belakang
const numberToMove = 9
input.sort((a,b) => {
if(b===9) {
return -1
} else {
return 0
}
})
console.log(input) //output: [-1, 8, 3, -2, 4, -3, 9, 9, 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment