Q: Filter By Age - JavaScript Task

+4 votes

I need to write a JS function that stores the name and age of two persons in objects and then filters them by minimum age.

The input comes as five arguments:

  • The first element is the minimum age.
  • The second and third elements are the name and age of the first person
  • The fourth and fifth elements – the name and age of the second person.


12, 'Ivan', 15, 'Asen', 9   


{ name: 'Ivan', age: 15 }

The three age parameters will be numbers, the names will be strings. The output should be printed to the console.

asked in JavaScript category by user golearnweb
edited by user golearnweb

1 Answer

+4 votes

Here is my solution:

function filterByAge(minAge, nameA, ageA, nameB, ageB) {
    var personA = {name: nameA, age: Number(ageA)};
    var personB = {name: nameB, age: Number(ageB)};

    if (personA.age >= minAge) {

    if (personB.age >= minAge) {

filterByAge(12, "Ivan", 15, "Asen", 9);


answered by user eiorgert
edited by user golearnweb