Moving to the End

Published by Helen Yu in

Write a function that moves all elements of one type to the end of the array.

Examples

move_to_end([1, 3, 2, 4, 4, 1], 1) ➞ [3, 2, 4, 4, 1, 1]
# Move all the 1s to the end of the array.

move_to_end([7, 8, 9, 1, 2, 3, 4], 9) ➞ [7, 8, 1, 2, 3, 4, 9]

move_to_end(["a", "a", "a", "b"], "a") ➞ ["b", "a", "a", "a"]

Notes

Keep the order of the un-moved items the same.

Watch a quick demo on how Edabit works.