Allow categorization of this for PHP only.
So, yesterday I had an interview for the senior role of a software developer. I don’t remember this question very well, but I try to write it the way I remember.
Question
Write a function that takes a string as input and returns true if passed, false if not.
Requirements; (as far as I remember) - Only one type of input (string).
- The String parameter must be passed by reference.
- There is no variable inside the function, it means that if the pair is called $ str manipulation, then you need to do this, I did not like using the second variable to set reverseStr, etc.
- No cycle of each character in the line, he specifically said, so as not to go through each character in the line.
- There is no PHP built-in function, I think it was ok with (strlen)
My answer (no, he didn’t like it)
$str = 'this is testing'; $length = strlen($str); $reverseStr = ''; for($i=$length-1; $i>=0; $i--) { $reverseStr .= $str[$i]; }
So, although this does work a little, he didn’t want me to go through each character to get reverseStr. I guess I needed to think of a recursive solution, get the last character of the string and index etc.etc. but I think about it as I write this, too late!
What do you guys think?
source share