【发布时间】:2015-11-23 21:34:25
【问题描述】:
我被作业的最后一点困住了。我试了几次,但我的代码没有通过测试。有人可以修改并指出我做错了什么吗?
# Implement the calculate_line_with_highest_frequency() method to:
#* calculate the maximum value for highest_wf_count contained by the LineAnalyzer objects in analyzers array
# and stores this result in the highest_count_across_lines attribute.
#* identifies the LineAnalyzer objects in the analyzers array that have highest_wf_count equal to highest_count_across_lines
# attribute value determined previously and stores them in highest_count_words_across_lines.
def calculate_line_with_highest_frequency
highest_count_across_lines = Hash.new(0)
@analyzers.each do |line|
line.content.split.each do |word|
highest_wf_count[word.downcase] +=1
end
end
@highest_count_across_lines = highest_wf_count.values.max
@highest_count_words_across_lines = Array.new
@analyzers.each do |line|
line.highest_count_across_lines.each do |word|
@highest_count_words_across_lines << line if highest_count_across_lines[word] == @highest_wf_count
end
end
【问题讨论】:
-
了解您要通过的测试会有所帮助。
-
如果这是一项作业,最好问问你的教授或导师。您提供的代码没有提供对作业的足够了解。
-
欢迎来到 Stack Overflow。请阅读“How to Ask”。我们需要更多信息:您的最小输入数据是多少,您需要什么输出?如果代码不起作用,您需要解释您打算让代码做什么以满足要求以及您看到它没有做什么。请不要指望我们会取代你的导师;根据您到目前为止所学的内容,他们更清楚您应该学习什么。我们不能只是跳进去。
标签: ruby-on-rails ruby