Skip to main content

Play our NQE Koan Challenge - Finding Nemo

  • May 29, 2025
  • 2 replies
  • 55 views

Tyson Henrie
Employee
Forum|alt.badge.img+2

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:["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"] }

];

 

Example Result

[Name,  Age, Pet…….]

 

 

Contributions: Unclaimed

2 replies

davetee
Community Manager
Forum|alt.badge.img
  • Community Manager
  • 28 replies
  • May 30, 2025

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 }

 


Forum|alt.badge.img
  • Ramping Up
  • 4 replies
  • June 16, 2025

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 }

 

The only tweak I see is to not involve network.devices. 

I replaced foreach device in network.devices with foreach x in [0]
 

And the usual things to do to minimize characters (not including comments in the NQE ….
 

foreach x in [0] let s = [{ n: "Tim", a: 21, t: ["dog", "mouse", "fish"]},{ n: "Mark", a: 19, t: ["dog", "fish", "cat"]},{ n: "Nina", a: 18, t: ["snake", "lizard"]},{ n: "Leroy", a: 24, t: ["fish"]},{ n: "Sally", a: 11, t: ["dog", "fish"]}] foreach p in s foreach t in p.t where p.a < 20 && t == "fish" select distinct {Name: p.n, Age: p.a, Pets: p.t}