Last active
March 22, 2020 03:35
-
-
Save krowter/a53999a7421b5c5dd6548f3e9b7078be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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