It's too simple to be awarded full marks. Expand it
/**
* @return true | false
* @param $val bool The bool to invert
* @desc Returns the
*/
function invert_bool($val){
if($val == true)
return false;
if($val == false)
return true;
}
Let's see how much we can earn "by the hour" by increasing the lines of code of the above example.
/**
* @return true | false
* @param $val bool The bool to invert
* @desc Returns the
*/
function invert_bool($val)
{
if($val == true)
return false;
if($val == false)
return true;
}
IanH.
January 10th, 2006
So
return !($val);
wouldn't suffice then.
Congratulations, IanH., you win the contract.
PHB
January 10th, 2006
/**
* @return true | false
* @param $val bool The bool to invert
* @desc Returns the
*/
function invert_bool($val){
if($val == true)
return false;
if($val == false)
return true;
}
____________
here's my one and only contribution to this exercise.
function invert_bool($val)
{
bool retVal = false;
if($val == true)
retVal = false;
else
{
if($val == false)
retVal == true;
else
retVal == false;
}
return retVal;
}
Jacob
January 10th, 2006
Right Simon,
One-liners are out of question.
I want documented answers [gnu style], with hyperlinks to describe every darn thing.
example answer:
try{
if($val.toString().equals(true))
{
return false;
}
else if($val.toString().notEquals(true))
{
return true
}
catch(Excception exObject)
{
print("THIS ERROR IS IMPOSSIBLE");
}
finally
{
__HALT;
}
This is roughly on-topic damn't. Why do Indians continually want to program and/or talk about programming in the off-topic area? No wonder we outsource so much to your hard working bastards.
Phil
January 10th, 2006
Amateurs!
/*
* @return true | false
* @param $val bool The bool to invert
* @desc Returns the inverse if the passed value
`* Expected values for $val:
* true: True
* false: False
*/
function invert_bool
(
$val // Value to invert
)
{
/*
* If the parameter is true...
*/
if
(
$val == true
)
{
/*
* Return false
*/
return false;
}
/*
* If the parameter is false...
*/
if
(
$val == false
)
{
/*
* Return true
*/
return true;
}
/*
* For all other values, assume it was false.
*/
return true;
}
DARN!!
This is off-topic. Let the infidel thread burn in hell.
I'm sorry, IanH., but upon further review, management has decided to award the contract to Mat.
Congratulations, Mat. Well-done, old man.
PHB
January 10th, 2006
Sadly I've actually worked places where that's not too far from the standard -- all parameters to everything had to be on a line of their own, every conditional had to be commented with what you're testing (generally with an explanation of why), and everything had 12 or so lines of comments MINIMUM at the top with copyright notices, who wrote it, who revised it, when, why, and all sorts. It was enough to make me cry...