use snake_case for method and variable names
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# Finds the smallest value in an array
|
# Finds the smallest value in an array
|
||||||
def findSmallest(arr)
|
def find_smallest(arr)
|
||||||
# Stores the smallest value
|
# Stores the smallest value
|
||||||
smallest = arr[0]
|
smallest = arr[0]
|
||||||
# Stores the index of the smallest value
|
# Stores the index of the smallest value
|
||||||
@@ -15,15 +15,15 @@ def findSmallest(arr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Sort array
|
# Sort array
|
||||||
def selectionSort(arr)
|
def selection_sort(arr)
|
||||||
newArr = []
|
new_arr = []
|
||||||
(0...(arr.length)).each do |i|
|
arr.length.times do
|
||||||
# Finds the smallest element in the array and adds it to the new array
|
# Finds the smallest element in the array and adds it to the new array
|
||||||
smallest = findSmallest(arr)
|
smallest = find_smallest(arr)
|
||||||
newArr.push(arr.delete_at(smallest))
|
new_arr.push(arr.delete_at(smallest))
|
||||||
end
|
end
|
||||||
newArr
|
new_arr
|
||||||
end
|
end
|
||||||
|
|
||||||
# 'p obj' is the same as 'puts obj.inspect'
|
# 'p obj' is the same as 'puts obj.inspect'
|
||||||
p selectionSort([5, 3, 6, 2, 10])
|
p selection_sort([5, 3, 6, 2, 10])
|
||||||
|
|||||||
Reference in New Issue
Block a user