-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Home
- [How to download a single folder from github repo?] (#q-how-to-download-a-single-folder-from-github-repo)
- [I am having trouble understanding the following problem given in the Flow of Control lecture] (#q-i-am-having-trouble-understanding-the-following-problem-given-in-the-flow-of-control-lecture)
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:
- Per technical requirement 8, the
Solution
class is supposed to have theanalyzers
array; which means that it has ALLLineAnalyzers
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)
- 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"]
```
A: The first test expects to find 3 printed lines when it runs the file module2_lesson2_formative.rb
. In order to pass the test, do not delete anything from the original file. Just add your solution to the end of this file.
A: You cannot download a single folder from the repo (as far as I know). You have 2 options:
- When you go to https://github.com/jhu-ep-coursera/fullstack-course1-module2 there is a green button in the top right "Clone or Download" - you can download a zip file of the repo and then extract what you need
- You can clone the repo by typing the following on the command line:
git clone https://github.com/jhu-ep-coursera/fullstack-course1-module2.git
times_2 = 2
times_2 *= 2 while times_2 < 100
puts times_2 #=>?
A: The best way to solve any problem is to break it up into smaller pieces. So we have essentially these three lines:
times_2 = 2
times_2 *= 2 while times_2 < 100
puts times_2
On line 1, we simply declare a variable of times_2 and assign it a value of 2.
On line 2, we have two pieces:
First one is times_2 *= 2.
This statement essentially is the short form for the following:
times_2 = times_2 * 2
So what we're doing here is taking times_2 and multiplying that by 2.
Next, we have the while modifier and the condition that follows, which is:
times_2 < 100
You can read more about the while modifier here. https://www.tutorialspoint.com/ruby/ruby_loops.htm
Essentially, when the 2nd line is executed, it first runs times_2 *= 2. Next, when it sees the while modifier, it checks to see if the condition is met. If the condition is met, then it repeats the first part of the statement which is times_2 *= 2. If the condition is not met, then it will move to the next line of code.
With this info, try to figure out the expected output!