저는 Ruby를 처음 사용하기 때문에 대답이 매우 간단합니다. 아니지만 내게루프는 마지막 항목 만 반환합니다.
문자열의 배열 (A)을 가져 와서 다른 문자열 배열 (B)과 비교하여 (A)의 주어진 문자열이 B 문자열의 부분 문자열로 존재하는지 확인합니다.
그러나 비교가 작동하는 것처럼 보입니다. 나는 마지막 (A) 문자열의 결과 만 비교합니다.
이것은 무엇입니까? 무시하는 경우, 그 다음
FILM_NAMES = [
'Baked Blue Tomatoes',
'Fried Yellow Tomatoes',
'The thing that ate my homework',
'In a world where',
]
문자열을 포함하는 모든 영화 이름을 찾을 : 영화 이름을 사용할 수있는 경우
def find_films_available_online(partial_film_name)
FILM_NAMES.find_all do |film_name|
film_name.downcase[partial_film_name.downcase]
end
end
p find_films_available_online('tomatoes')
# => ["Baked Blue Tomatoes", "Fried Yellow Tomatoes"]
p find_films_available_online('godzooka')
# => []
알아하려면 영화 이름의 목록을 감안할 때
def checkIfAvailableOnline(film)
puts "Looking for " + film
lowerCaseFilm = film.downcase
#iterate through the linesarray scanning for the film in question
for line in @linesArray
#get the line in lowercase
lowerCaseLine = line.downcase
#look for the film name as a substring within the line
results = lowerCaseLine.scan(lowerCaseFilm)
if results.length > 0
@availableOnlineArray << results
end
end
end
#-----------------------------------------
listFilmsArray.each {|line| checkIfAvailableOnline(line)}
일부 테스트 코드가 도움이 될 수 있습니다. 코드를 어떻게 테스트 했습니까? –