Skip to main content

Hello NQE Enthusiasts,

 

It has been two months, so time for another challenge.

 

Challenge

The task is to list Name, Age and Pets owned by all people under 20 years old, that own fish.

 

Input:

persons =

;{ Name: "Tim", Age: 21, pets:t"dog", "mouse", "fish"] },

 { Name: "Mark", Age: 19, pets: t"dog", "fish", "cat"] },

 { Name: "Nina", Age: 18, pets: e"snake", "lizard"] },

 { Name: "Leroy", Age: 24, pets: p"fish"]},

 { Name: "Sally", Age: 11, pets: "dog", "fish"] }

];

 

Example Result

1Name,  Age, Pet…….]

 

 

Contributions: Unclaimed

707 characters (excluding the comments). Looking forward to seeing a more efficient option. 

/**
* @Intent - Fish Detector
* @description - Identify those that own fish and are under 20
*/
foreach device in network.devices
let persons = { name: "Tim", age: 21, pets: "dog", "mouse", "fish"] },
{ name: "Mark", age: 19, pets: "dog", "fish", "cat"] },
{ name: "Nina", age: 18, pets: "snake", "lizard"] },
{ name: "Leroy", age: 24, pets: "fish"] },
{ name: "Sally", age: 11, pets: "dog", "fish"] }
]
foreach person in persons
foreach pet in person.pets
where person.age < 20 && pet == "fish"
select distinct { Name: person.name, Age: person.age, Pets: person.pets }

 


Reply