Answers for "likes instagram system js"

0

likes instagram system js

function likes(names){
    let aux = " like this";
    if(names.length === 0){
        return "no one likes this";
    }else if(names.length == 1){
        return names[0] + " likes this";
    }else if(names.length == 2){
        return names[names.length - 2] + " and " + names[names.length - 1] + aux;
    }
    else if(names.length == 3){
        return names[names.length - 3] + ", " + names[names.length - 2] + " and " + names[names.length - 1] + aux;
    }
    else {
        let others = names.length - 2;
        return names[0] + ", " + names[1] + " and " + others + " others" + aux;
    }
}

console.log(likes([]));
console.log(likes(['Peter']));
console.log(likes(['Jakob' , 'Alex']));
console.log(likes(['Max', 'Jacob', 'Peter']));
console.log(likes(['Max', 'Jacob', 'Peter', 'Bob', 'Alex']));
console.log(likes(['Max', 'Jacob', 'Peter', 'Bob', 'Alex', 'Isabelle', 'Elizabeth']));
Posted by: Guest on October-07-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language