Tuesday, September 25, 2007

Source of Hope

I have really been progressing well withth javascript that I have been learning lately. And was pleased to be able to solve a problem that I stumbled across on a blog.

The nblpg is written by a software devloper, and is abit heavy for me, but I checked it out becuause it was a link:
coding horror
on a helpful forum users response over at Wrox javascript forums. Any here is an extract of the article:



After a fair bit of trial and error I've discovered that people who struggle to code don't just struggle on big problems, or even smallish problems (i.e. write a implementation of a linked list). They struggle with tiny problems.


So I set out to develop questions that can identify this kind of developer and came up with a class of questions I call "FizzBuzz Questions" named after a game children often play (or are made to play) in schools in the UK. An example of a Fizz-Buzz question is the following:


Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".


Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes. Want to know something scary? The majority of comp sci graduates can't. I’ve also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution.


To be honest I think that the claim is well and truly exaggerated, but it was nonetheless inspiring becuase as I read the question I sauid to myself I think I can do that , so I open up notepad and hammered out a solution:


var nums=new Array();
function FizzBuzzTest()
{
for(i=0;i&lt101;i++)
{
nums[i]=i;
if(i%3==0)
{
nums[i]="Fizz";
}
if(i%5==0)
{
nums[i]="Banger";
}
if(i%5==0&&i%3==0)
{
nums[i]="FizzBanger";
}
document.write("<>"+nums[i]+"

");
}
}

Just had to post this becuase it felt so good, now where is my Biscut?




No comments: