Skip to content

2020-6: Move to the Front

Write a function that, given a right argument which is an integer vector and a left argument which is an integer scalar, reorders the right argument so any elements equal to the left argument come first while all other elements keep their order.

💡 Hint: The Grade Up function ⍋Y could be helpful for this problem.

Examples:

      3 (your_function) 1 2 3 4 1 3 1 4 5
3 3 1 2 4 1 1 4 5

      3 (your_function) ,1   ⍝ the , makes 1 into a vector
1

      42 (your_function) ⍬   ⍝ empty right argument gives empty result
your_function ←

Solutions

Video Thumbnail YouTube

Chat transcript Code on GitHub