Comma quibbling: Difference between revisions
→{{header|PHP}}: Don't modify the array; eliminate separate 2-item case (which the 3+-item case already handled); refactor to use switch instead of if/then
(→{{header|UNIX Shell}}: Add Zsh-specific version) |
(→{{header|PHP}}: Don't modify the array; eliminate separate 2-item case (which the 3+-item case already handled); refactor to use switch instead of if/then) |
||
Line 3,425:
<syntaxhighlight lang="php"><?php
function quibble($arr) {
case 0:
return '{}';
case 1:
return
return '{'.$arr[0].' and '.$arr[1].'}';▼
default:
$right = array_slice($arr, -1)[0];
}▼
▲ }
}
Line 3,451 ⟶ 3,454:
foreach ($tests as $test) {
echo quibble($test) . PHP_EOL;
}
{{out}}
<pre>{}
|