Skip to content
Aina Pinto edited this page Jan 8, 2016 · 18 revisions

FAQs - Module 2

Calculate Maximum Word Frequency

Q: Why do I get a 'NoMethodError' highest_wf_words?

A: The error:

1) Solution#calculate_line_with_highest_frequency calculates highest 
   count words across lines to be will, it, really
  
  ...
  
  NoMethodError:
    undefined method 'highest_wf_words' for "really":String

The explanation:

  1. Per technical requirement 8, the Solution class is supposed to have the analyzers array; which means that it has ALL LineAnalyzers objects.

a. highest_count_words_across_lines which is ALSO an array of LineAnalyzers, but only those objects whose words have the highest frequency. It is NOT an array of strings. So, basically, it is a SUBSET of analyzers array.

b. Per technical requirement 12, after calling calculate_line_with_highest_frequency method, the highest_count_words_across_lines attribute of the Solution class should be populated (see the item 1.a what should be contained inside the highest_count_words_across_lines attribute)

  1. Here is what the following line
solution.highest_count_words_across_lines.map(&:highest_wf_words).flatten

is doing when testing your solution:

Let's break it up:

**a.** `solution.highest_count_words_across_lines` - looks up the `highest_count_words_across_lines` attribute of `solution`. This attribute should contain... see **1.a**.

**b.** `map(&:highest_wf_words)` - is equivalent to `map { |elem| elem.highest_wf_words }`

It basically says, "extract `highest_wf_words` property of each element inside `highest_count_words_across_lines`" - which makes sense, since each element in there is a `LineAnalyzer` object - "and create another array of just `highest_wf_words` values"

**c.** `highest_wf_words` property is itself an **array**! So, if you have something like the following:
```
[["one", "two"], ["three"], ["five", "six"]] 
```
What `flatten` will do is to make it one happy array as follows 
```
["one", "two", "three", "four", "five", "six"]
```
Clone this wiki locally