Array Mapping and Filters Assignment

 <!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
   
    <title>Document</title>
</head>
<body>
   

    <script src="am.js"></script>
</body>
</html>


// JAVA SCRIPT FILE


const users = [
    {
        name: "Akash Sharma",
        age: 17,
        gender: "Male",
        location: "Delhi, India"
    },
    {
        name: "Neha Patel",
        age: 16,
        gender: "Female",
        location: "Mumbai, India"
    },
    {
        name: "Rajesh Singh",
        age: 17,
        gender: "Male",
        location: "Bangalore, India"
    },
    {
        name: "Priya Gupta",
        age: 20,
        gender: "Female",
        location: "Kolkata, India"
    },
    {
        name: "Vikram Kumar",
        age: 15,
        gender: "Male",
        location: "Chennai, India"
    },
    {
        name: "Deepak Verma",
        age: 31,
        gender: "Male",
        location: "Hyderabad, India"
    },
    {
        name: "Anjali Reddy",
        age: 27,
        gender: "Female",
        location: "Pune, India"
    },
    {
        name: "Sneha Desai",
        age: 29,
        gender: "Female",
        location: "Ahmedabad, India"
    },
    {
        name: "Amit Dubey",
        age: 33,
        gender: "Male",
        location: "Jaipur, India"
    },
    {
        name: "Rohit Mehta",
        age: 26,
        gender: "Male",
        location: "Surat, India"
    },
    {
        name: "Pooja Jain",
        age: 30,
        gender: "Female",
        location: "Lucknow, India"
    },
    {
        name: "Rakesh Mishra",
        age: 34,
        gender: "Male",
        location: "Kanpur, India"
    },
    {
        name: "Sarita Singh",
        age: 36,
        gender: "Female",
        location: "Nagpur, India"
    },
    {
        name: "Rishi Khanna",
        age: 38,
        gender: "Male",
        location: "Indore, India"
    },
    {
        name: "Vidya Sharma",
        age: 37,
        gender: "Female",
        location: "Varanasi, India"
    }
];


function isadult(user){
    if(user.age>=18)
        return true;
    else{
        return false;
    }

}
// function isAdult(user) {
//     return user.age >= 18;
// }
// adultUsers = users.filter(isAdult);
adultUsers=users.filter((user)=>{

    return isadult(user)==true;


})


getFullName=users.map((user)=>{


    return user.name +" "+user.location;

})

userNames=users.map((user)=>{

    return user.name


})


function filterByGender(user,gender){
    if(user.gender==gender){

        return true;

    }
    else{

        return false;
    }

}

getFullName=users.filter((user)=>{
    return filterByGender(user,'Female');
}).map((user)=>{
    return user.name;

})

console.log(getFullName);


output:-





Comments

Popular posts from this blog

Rolling Dice

Basics Of Java Script Till DOM Beggining