Skip to content

Instantly share code, notes, and snippets.

@krowter
Last active March 22, 2020 03:35
Show Gist options
  • Save krowter/a53999a7421b5c5dd6548f3e9b7078be to your computer and use it in GitHub Desktop.
Save krowter/a53999a7421b5c5dd6548f3e9b7078be 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
//array nines berisi bilangan dalam input yang sama dengan 9
const nines = input.filter((number) => number === numberToMove)
//array nines berisi bilangan dalam input yang tidak sama dengan 9
const notNines = input.filter((number) => number !== numberToMove)
//gunakan concat untuk menggabungkan nilai
const result = notNines.concat(nines)
console.log(result) //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