Hacker News new | ask | show | jobs
by pixeloution 5388 days ago

  <?php

  $string = "aeiouxabcd";
  $checkfor = array('a','e','i','o','u');
  $count = 0;

  for($x = 0; $x < strlen($string); $x++) {
    if(in_array($string[$x], $checkfor)) {
  	 $count++;
    }
  }

  echo $count . "\n";
Am I hired? Or do I lose cool points for PHP?
3 comments

Every time FizzBuzz problems come up among engineers, people race to solve them and post their answers, then compete to see who can write increasingly more nifty answers for a question which does not seek niftiness at all.

I'm all for intellectual gamesmanship, but these are our professional equivalent of a doctor being asked to identify the difference between blood and water. You can do it. We know. Demonstrating that you can do it is not the point of the exercise. We do it to have a cheap-to-administer test to exclude people-who-cannot-actually-program-despite-previous-job-titles from the expensive portions of the hiring process.

    <?php
    echo strlen(preg_replace('/[^aeiou]/i', '', 'hello world'));
You lose the cool points for not using a regex, I'm afraid.