Function should not modify original array.