← Back to challenges

Moving to the End

JavaScriptHardarrayshigher_order_functions

Instructions

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

Examples

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

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

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

Notes

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

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Calculate the Shortest Distance Between Two Points