I'm returning the index of the smallest integer in an array. I found a solution from this forum. Here is what I did:
require 'amatch'
include Amatch
ingredients_arr = [
"All purpose", "Ammoniaco", "Assorted sprinkles", "Baking Powder",
"Baking soda", "Banana", "Banana flavor", "Bread improver", "Brown Sugar",
"Buko pandan flavor", "Butter", "Butter flavor", "Butter oil subs",
"Cake Flour", "Cake emulsi\nfier", "Canyon baking powder", "Cheese",
"Chiffon oil", "Choco flavor", "Choco spri\nnkles", "Cocoa (imp)",
"Cocoa (loc)", "Coconut", "Condensada", "Cooking\nOil", "\n Corn Starch",
"Dessicated", "Dutch choco fudge premium", "Dutch cocoa premium", "Egg",
"Evaporad\n a (B)", "Evaporada (S)", "Evaporadaorated\n(B)", "First Class",
"Food color", "Glucose", "Go\n ld coin", "Heart sprinkles", "LPG", "Lard",
"Linga", "Margarine", "Mocha flavor", "Mongo paste red", "Onion", "Ovalet",
"Powdered sugar", "Rhum", "Royal", "Salt", "Sibuyas", "Skim milk (h-end)",
"Skim milk (l-end)", "\n Star sprinkles", "Strawberry flavor",
"Styro (l. plan)", "Super syrup", "Taba", "Tartar", "\n Third Class",
"Ube Paste", "Ube flavor", "Vanilla", "Vanilla 1G", "Vivid icing",
"Wash Sugar", "Water", "White Sugar"
]
i, ingredient = 1, "Flour"
ing_array = Array.new
until ingredient == ""
puts "Enter ingredient #{i}: "
ingredient = gets.chomp
ing_array << ingredient
i += 1
end
ing_array.pop
m = Sellers.new("margarine")
no_words = ing_array.length
ing_index_arr = Array.new
i = 0
while i < no_words
rating_arr = Array.new
m = Sellers.new(ing_array[i])
j = 0
while j < ingredients_arr.length
x = m.match(ingredients_arr[j])
rating_arr << x
j += 1
end
y = rating_arr.each.with_index.find_all{|a, i| a == rating_arr.min }.map{|a, b| b}
ing_index_arr << y
i += 1
end
ing_index_arr # => [[0], [67], [4]]
but I need something like this:
[0, 67, 4]
Hope someone can help me.