Posting this here looking for constructive criticism. If anyone's got any tips/advice on things I could've done better/differently, please feel free to say so.
The code challenge was:
I dunno if I got the bonus, although I DID get a lotta much needed experience using numpy for certain things, so at least there's that.
Anyway lemme know what you guys think.
The code challenge was:
- Prompt: Reverse an array. A classic code interview question.
- Difficulty: easy
- Languages: no-restrictions
- Constraints: The function should take in any array and return that array in reverse. If your language has a native .reverse() function cannot use it because this is a test of complexity and not how well you can use a function!
- Bonus: Do this without allocating any extra memory. This is called modifying the array "in-place"!
Code
# reverse an array challenge
# gotta have numpy
import numpy as np
# big daddy string to get things done
def string_to_array_to_reversed_array():
# for handling user input
def user_input_function(user_input): # user_input to take in the input when called
user_input = list(user_input.replace(" ", "")) # user_input is reassigned it's input string as a list, while user_input.replace trims any white space out
return np.array(user_input, order = 'C') # return user_input list as an array in contiguous order to array_arg parameter in reverse_array function
# for reversing the array
def reverse_array(array_arg): # array_arg takes in the return from user_input_function
return np.flipud(array_arg) # FLIPS THE ARRAY, DOESN'T REVERSE IT. YOU SEE THE .flipud part right?. NOTHING WAS SAID ABOUT FLIPPING. ONLY REVERSING.
# x assigned to take in final return value and store it for printing
x = reverse_array(user_input_function(input("Please type in a single word as a string: "))) # get user input
return x # RESULTS ARE IN!
# call "main" function and make shit happen, store in reversed_array for printing.
reversed_array = string_to_array_to_reversed_array()
print(reversed_array)I dunno if I got the bonus, although I DID get a lotta much needed experience using numpy for certain things, so at least there's that.
Anyway lemme know what you guys think.



![[Image: main.gif]](https://i.ibb.co/W2WKpzj/main.gif)
![[Image: 3943c24fb6058003233768a9747351d2.png]](https://fontmeme.com/permalink/171027/3943c24fb6058003233768a9747351d2.png)