Answers for "Codewars 01. Who likes it"

0

Codewars 01. Who likes it

function likes(array $names){

if(empty($names)){
    
    return "no one likes this";
 }   
else if(count($names) === 1 ){
    
    return "$names[0] likes this";
  
}else if(count($names) === 2 ){
    
    return "$names[0] and $names[1] like this";
}
else if(count($names) === 3 ){
    
    return "$names[0], $names[1] and $names[2] like this";
    
}else if(count($names) === 4 ){
    
    return "$names[0], $names[1] and ". (count($names) -2) ." others like this"; 
};
}
echo likes( [ 'Alex', 'Jacob', 'Mark', 'Max' ] );
Posted by: Guest on April-02-2021

Browse Popular Code Answers by Language