I'm passing the argument in a suitable array-format for convenience and brevity:
promo←{(⊂'')~⍨(⊂⍵){(⍺[1]≤+/⍺[2]≤2⊃⍵)/1⊃⍵}¨3⊃⍵}
promo 5 20(('John Doe'(22 30 11 17 15 15 52 27 12))('Jane Doe'(5 17 30 33 40 22 26 10 11 45))) ┌────────┐ │Jane Doe│ └────────┘ promo 2 50 (('Joey Bonzo'(22 67 53 29))('Jennifer Bonzo'(51 19))) ┌──────────┐ │Joey Bonzo│ └──────────┘ promo 3 15 (('Natsumi Sakamoto'(15 15 14))('Gorou Hironaka'(15 15 15))('Shinju Tanabe'(120 40))) ┌──────────────┐ │Gorou Hironaka│ └──────────────┘
Since the task was shown with JSON-Data, I want to also show how to tackle this with JSON-Data in APL.
promo2←{(⊂'')~⍨(⊂⍵.(min_orders min_price)){(⍺[1]≤+/⍺[2]≤⍵.hist)/⍵.id}¨⍵.customers}
Test1←⎕JSON'{"min_orders":5,"min_price":20,"customers":[{"id":"John Doe","hist":[22, 30, 11 ,17 ,15 ,52, 27 ,12]},{"id":"Jane Doe","hist":[5 ,17 ,30 ,33, 40, 22, 26, 10, 11 ,45]}]}' promo2 Test1 ┌────────┐ │Jane Doe│ └────────┘ Test2←⎕JSON'{"min_orders":2,"min_price":50,"customers":[{"id":"Joey Bonzo","hist":[22,67,53,29]},{"id":"Jennifer Bonzo","hist": [51,19]}]}' promo2 Test2 ┌──────────┐ │Joey Bonzo│ └──────────┘ Test3←⎕JSON'{"min_orders":3,"min_price":15,"customers":[{"id":"Natsumi Sakamoto","hist":[15,15,14]},{"id":"Gorou Hironaka","hist": [15,15,15]},{"id":"Shinju Tanabe","hist":[120,40]}]}' promo2 Test3 ┌──────────────┐ │Gorou Hironaka│ └──────────────┘
Feel free to experiment and Try it online! ;)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
APL - Solution 1 (using Dyalog APL)
I'm passing the argument in a suitable array-format for convenience and brevity:
Output:
APL - Solution 2
Since the task was shown with JSON-Data, I want to also show how to tackle this with JSON-Data in APL.
Testing
Feel free to experiment and Try it online! ;)