fizzbuzz

31 views
Skip to first unread message

Stephen Stewart

unread,
May 10, 2012, 5:49:11 AM5/10/12
to belf...@googlegroups.com
I was waiting for something to build last night and thought I'd have a go at Fizbuzz. It escalated real quick...

http://jsfiddle.net/earnubs/KK3Wg/ # fizzbuzz IV: A New Case
http://jsfiddle.net/earnubs/mUKUe/ # fizzbuzz Holiday Special

davidlowry

unread,
May 10, 2012, 6:09:40 AM5/10/12
to belf...@googlegroups.com
Is there a story behind this? Never 'erd of the Fizzbuzz.

James Hughes

unread,
May 10, 2012, 6:10:48 AM5/10/12
to belf...@googlegroups.com
For realz?  FizzBuzz is a fairly well established kata and/or interview question.

--
You received this message because you are subscribed to the Google Groups "belfastjs" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/belfastjs/-/vIXVxRQhWb0J.
To post to this group, send an email to belf...@googlegroups.com.
To unsubscribe from this group, send email to belfastjs+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/belfastjs?hl=en-GB.

James Hughes

unread,
May 10, 2012, 6:11:00 AM5/10/12
to belf...@googlegroups.com
For realz?  FizzBuzz is a fairly well established kata and/or interview question.

On Thursday, 10 May 2012 at 11:09, davidlowry wrote:

--

davidlowry

unread,
May 10, 2012, 6:18:03 AM5/10/12
to belf...@googlegroups.com
Ironically enough... I have read that article(!)


To unsubscribe from this group, send email to belfastjs+unsubscribe@googlegroups.com.
To unsubscribe from this group, send email to belfastjs+unsubscribe@googlegroups.com.

Jos Flores

unread,
May 10, 2012, 7:15:06 AM5/10/12
to belf...@googlegroups.com
It is funny how a small problem like that could keep us entertained for hours.
Have you tried test driving it? it might take you to a whole different
set of solutions, separating the algorithm from your implementation
reqs, bringing in patterns (namespace, module), and so on.

cheers,
José


On 10 May 2012 11:18, davidlowry <djl...@gmail.com> wrote:
> Ironically enough... I have read that article(!)
>
>
>
>
>
> On Thursday, 10 May 2012 11:11:00 UTC+1, James Hughes wrote:
>>
>> For realz?  FizzBuzz is a fairly well established kata and/or interview
>> question.
>>
>>
>> See http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html for
>> some background
>>
>> On Thursday, 10 May 2012 at 11:09, davidlowry wrote:
>>
>> Is there a story behind this? Never 'erd of the Fizzbuzz.
>>
>>
>> On Thursday, 10 May 2012 10:49:11 UTC+1, Stephen Stewart wrote:
>>
>> I was waiting for something to build last night and thought I'd have a go
>> at Fizbuzz. It escalated real quick...
>>
>> http://jsfiddle.net/earnubs/GgHmh/ # fizzbuzz I
>> http://jsfiddle.net/earnubs/ucn5K/ # fizzbuzz II
>> http://jsfiddle.net/earnubs/WY9kX/ # fizzbuzz III
>> http://jsfiddle.net/earnubs/KK3Wg/ # fizzbuzz IV: A New Case
>> http://jsfiddle.net/earnubs/mUKUe/ # fizzbuzz Holiday Special
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "belfastjs" group.
>> To view this discussion on the web, visit
>> https://groups.google.com/d/msg/belfastjs/-/vIXVxRQhWb0J.
>> To post to this group, send an email to belf...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> belfastjs+...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/belfastjs?hl=en-GB.
>>
>>
>
> On Thursday, 10 May 2012 11:11:00 UTC+1, James Hughes wrote:
>>
>> For realz?  FizzBuzz is a fairly well established kata and/or interview
>> question.
>>
>>
>> See http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html for
>> some background
>>
>> On Thursday, 10 May 2012 at 11:09, davidlowry wrote:
>>
>> Is there a story behind this? Never 'erd of the Fizzbuzz.
>>
>>
>> On Thursday, 10 May 2012 10:49:11 UTC+1, Stephen Stewart wrote:
>>
>> I was waiting for something to build last night and thought I'd have a go
>> at Fizbuzz. It escalated real quick...
>>
>> http://jsfiddle.net/earnubs/GgHmh/ # fizzbuzz I
>> http://jsfiddle.net/earnubs/ucn5K/ # fizzbuzz II
>> http://jsfiddle.net/earnubs/WY9kX/ # fizzbuzz III
>> http://jsfiddle.net/earnubs/KK3Wg/ # fizzbuzz IV: A New Case
>> http://jsfiddle.net/earnubs/mUKUe/ # fizzbuzz Holiday Special
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "belfastjs" group.
>> To view this discussion on the web, visit
>> https://groups.google.com/d/msg/belfastjs/-/vIXVxRQhWb0J.
>> To post to this group, send an email to belf...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> belfastjs+...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/belfastjs?hl=en-GB.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "belfastjs" group.
> To view this discussion on the web, visit
> https://groups.google.com/d/msg/belfastjs/-/NySHD5L8J4cJ.
>
> To post to this group, send an email to belf...@googlegroups.com.
> To unsubscribe from this group, send email to
> belfastjs+...@googlegroups.com.

Alvyn McQuitty

unread,
May 10, 2012, 7:18:11 AM5/10/12
to belf...@googlegroups.com
As I am a coding/javascript newcomer I first came across FizzBuzz on codeacademy. Looking forward to finding more problems like it.

Jos Flores

unread,
May 10, 2012, 7:23:03 AM5/10/12
to belf...@googlegroups.com
Alvyn, there's 21 similar links at the end of this post:
http://codekata.pragprog.com/2007/01/code_kata_backg.html

have fun! :)
José

Alvyn McQuitty

unread,
May 10, 2012, 7:24:39 AM5/10/12
to belf...@googlegroups.com
Thanks José!

Stephen Stewart

unread,
May 10, 2012, 7:31:34 AM5/10/12
to belf...@googlegroups.com
José,

To be test driven I'd need say, a valid string to assert against
"12fizz4buzzfizz...", to get a valid string I'd need a working
implementation, no?

Stephen
Stephen Stewart
stephen...@carisenda.com

Toby Osbourn

unread,
May 10, 2012, 7:32:48 AM5/10/12
to belf...@googlegroups.com
We are looking for a Web Dev in my company and I sent out some interview questions that included asking them to implement FizzBuzz in JavaScript (renamed to avoid a quick google)

One answer we got back had literally an error on each line and didn't run, it was almost impressive!

--
You received this message because you are subscribed to the Google Groups "belfastjs" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/belfastjs/-/yr6MHATMSI8J.

To post to this group, send an email to belf...@googlegroups.com.
To unsubscribe from this group, send email to belfastjs+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/belfastjs?hl=en-GB.

Jos Flores

unread,
May 10, 2012, 7:52:43 AM5/10/12
to belf...@googlegroups.com
Stephen, not really, your test cases can assert on a single reply to
the algorithm... and that is where your solution would be totally
changed.

You are basing your solution in the fact that you are counting from 1
to 100 (which right now is a requirement for you, and it can change),
but you are not isolating the algorithm that computes FizzBuzz, but
embedding it into that initial requirement. The solution is very
coupled (I know it's only fizzbuzz!).

If you had something like FizzBuzz.say(1), then you can assert that
the result is '1'. FizzBuzz.say(3) would expect 'Fizz'.
Your general solution would be something like a for loop to
MAX_FIZZBUZZ calling FizzBuzz.say(i) inside. Now all your pieces are
modularised and can evolve and change separately. You could even reuse
your fizzbuzz module in... well, not in many other problems I'd say :D

Is this overkill for a problem like Fizz Buzz? definitely, but are you
trying to solve fizzbuzz or are you deliberately practicing your
coding skills? that, of course, is up to you.

cheers,
José

Stephen Stewart

unread,
May 10, 2012, 8:11:50 AM5/10/12
to belf...@googlegroups.com
Something like this maybe?

http://jsfiddle.net/earnubs/S8XXw/


On Thursday, May 10, 2012 12:52:43 PM UTC+1, Jos wrote:
Stephen, not really, your test cases can assert on a single reply to
the algorithm... and that is where your solution would be totally
changed.

You are basing your solution in the fact that you are counting from 1
to 100 (which right now is a requirement for you, and it can change),
but you are not isolating the algorithm that computes FizzBuzz, but
embedding it into that initial requirement. The solution is very
coupled (I know it's only fizzbuzz!).

If you had something like FizzBuzz.say(1), then you can assert that
the result is '1'. FizzBuzz.say(3) would expect 'Fizz'.
Your general solution would be something like a for loop to
MAX_FIZZBUZZ calling FizzBuzz.say(i) inside. Now all your pieces are
modularised and can evolve and change separately. You could even reuse
your fizzbuzz module in... well, not in many other problems I'd say :D

Is this overkill for a problem like Fizz Buzz? definitely, but are you
trying to solve fizzbuzz or are you deliberately practicing your
coding skills? that, of course, is up to you.

cheers,
José
[...]

Jos Flores

unread,
May 10, 2012, 8:38:51 AM5/10/12
to belf...@googlegroups.com
yeah, you do have an algorithm in there. It still being declared in
the global object but you always need at least one global anyway. I
like to use namespace or module for that, in case your reqs change
again and you need more functions, but you get the idea.
Have you ever tried Jasmine? could make your life easier when coding:
http://pivotal.github.com/jasmine/
There are tons of other testing frameworks, I'm not really partial to
any, but if you use node, then jasmine-node makes it really painless
to work with Jasmine outside of the browser.

cheers,
José
> --
> You received this message because you are subscribed to the Google Groups
> "belfastjs" group.
> To view this discussion on the web, visit
> https://groups.google.com/d/msg/belfastjs/-/-TYN9MEK8jwJ.
Reply all
Reply to author
Forward
0 new messages