-
-
Save harmlessprince/03bb86d4d73c584728c5ec55c56961ca to your computer and use it in GitHub Desktop.
This filters out a given number out from an array and returns the new length of the array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function filter_val( array $arr, int $val) : int{ | |
$output = array_filter($arr, function($value) use ($val) { | |
return $value - $val != 0; | |
}); | |
return count($output); | |
} | |
$array = [5,2,2,5,3]; | |
$val = 5; | |
print_r(filter_val($array, $val)); |
Edge cases basically are those unexpected cases that your program should still be able to handle. For example, invalid input, null
input etc.
I agree with the type hinting for the input. but right now if I did this:
print_r(filter_val(NULL, 3));
Your code will not handle the NULL
input gracefully.
Well, Understood, I guess the type hinting doesn't help the average user much...
Thanks for the review, Really appreciate
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the review, I really appreciate.
However if I may ask,