Skip to content

Instantly share code, notes, and snippets.

@bparanj
Created August 19, 2020 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bparanj/7b7eb6354c2361e396ae6a0f066628b5 to your computer and use it in GitHub Desktop.
Save bparanj/7b7eb6354c2361e396ae6a0f066628b5 to your computer and use it in GitHub Desktop.
def create_target_array(nums, index)
result = []
i = 0
while result.size < nums.size
result.insert(index[i], nums[i])
i += 1
end
result
end
@bparanj
Copy link
Author

bparanj commented Aug 19, 2020

Refactored code:

def create_target_array(nums, index)
    result = []
    
    nums.each_with_index do |item, i|
      result.insert(index[i], item)  
    end
        
    result
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment