Was hoping someone could help explain the the logic behind the code below. I understand most it of other than when concatenating part[0] into initials. We split the string into an array, in this case (“Kelvin Bridges”) into [“Kelvin”, “Bridges”]. Isn’t “Bridges” technically at an index of 1? Or does |part| evaluate “Kelvin” and "Bridges as separate arrays?
def to_initials(name)
parts = name.split(" ")
initials = ""
parts.each { |part| initials += part[0] }
return initials
end
puts to_initials("Kelvin Bridges") # => "KB"