请比较这 2 个代码(第一个返回正确的 false 值,第二个返回 true 值)代码的唯一区别是 %w。为什么 %w 会导致这个问题?
#1
def ordered_vowel_word?(word)
vowels = ["a", "e", "i", "o", "u"]
letters_arr = word.split("")
vowels_arr = letters_arr.select { |l| vowels.include?(l) }
(0...(vowels_arr.length - 1)).all? do |i|
vowels_arr[i] <= vowels_arr[i + 1]
end
end
ordered_vowel_word?("complicated")
#2
def ordered_vowel_word?(word)
vowels = %w[a, e, i, o, u]
letters_arr = word.split("")
vowels_arr = letters_arr.select { |l| vowels.include?(l) }
(0...(vowels_arr.length - 1)).all? do |i|
vowels_arr[i] <= vowels_arr[i + 1]
end
end
ordered_vowel_word?("complicated")