This challenge was inspired by Yeah But No But Yeah.
maxb´s colleague recently sent him the following piece of JavaScript as a joke:
let butScript = (nrOfButs) => {
for(var i = 0; i < nrOfButs; i++){
if(i % 3 == 0){
console.log("Yeah")
}
if(i % 2 == 0){
console.log("But")
}
if(i % 3 == 1){
console.log("No")
}
}
}
Since the code is not only overly long but also incorrect, I´ll suggest to maxb´s boss to fire that guy and hire one of you folks instead.
I can´t guarantee anything; but I reckon there´ll be a decent wage, health insurance and possibly a company car in it. All You have to do is A) correct the code, so the Number of Buts printed is the same as asked in the parameter B) correct the grammar. (see below) C) make it as short as possible.
He might as well block my calls after that because he doesn´t like pennypickers; but who knows.
Input
a non-negative integer, in any convenient way
Output
Yeah
and No
, mostly separated by But
s. The code above and the examples below should clarify the pattern.
Output should never end in a But
.
And a sentence should always end with a stop (.
) or exclamation mark; i.e. put one after every No
that is directly followed by a Yeah
(without a But
) and one at the end of the output.
A single trailing "Yeah." may be printed (if you want to think positive), but that´s not a must.
You may print the output or return a list of strings.
Trailing blanks are acceptable, as well as a single leading or trailing newline.
examples (input => possible output)
input 0:
Yeah.
input 1:
Yeah
But
No.
input 2:
Yeah
But
No
But
Yeah.
input 3:
Yeah
But
No
But
Yeah
But
No.
Yeah! <optional>
...
input 5:
Yeah
But
No
But
Yeah
But
No.
Yeah
But
No
But
Yeah.
No Yeah
orYeah No
. 2. A dot should be added at the very end. 3. A single line only containingYeah
orNo
should be removed. 4. When a sentence ends with aBut
theBut
should be removed? (not sure about this fourth one) \$\endgroup\$n=0
be empty?.. It won't go into thefor(var i = 0; i < nrOfButs; ...
loop, so won't print anything there. And there is also the rule "A single trailing "Yeah." should be avoided." to consider. There are a bit too many unanswered questions, so I've voted to close as unclear for now.. Might change after some clarification and better (bullet-point) specified rules or step-by-step examples of the given test cases. \$\endgroup\$