Last active
February 10, 2023 03:47
-
-
Save Lzyct/babfc41477ce206593d9d3825e6fe140 to your computer and use it in GitHub Desktop.
Guest Gift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const wishlist = [ | |
| { name: "Mini Puzzle", size: "small", clatters: "yes", weight: "light" }, | |
| { name: "Toy Car", size: "medium", clatters: "a bit", weight: "medium" }, | |
| { name: "Card Game", size: "small", clatters: "no", weight: "light" } | |
| ]; | |
| const presents = [ | |
| { size: "medium", clatters: "a bit", weight: "medium" }, | |
| { size: "small", clatters: "yes", weight: "light" }, | |
| ]; | |
| function guestGift(wishlist, presents) { | |
| var result = presents.map(function(e, _) { | |
| return wishlist.find( | |
| (element, _) => (element['size'].toString() == e['size'].toString() && | |
| element['clatters'].toString() == e['clatters'].toString() && | |
| element['weight'].toString() == e['weight'].toString()), | |
| )['name']; | |
| }); | |
| return result; | |
| } | |
| console.log(guestGift(wishlist, presents)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Quiz from : https://gist.github.com/hafizkhairudin/4587d3c06e2903540b17bbc5b667cf44 | |
| void main() { | |
| List<Map<String, dynamic>> wishList = [ | |
| { | |
| "name": "Mini Puzzle", | |
| "size": "small", | |
| "clatters": "yes", | |
| "weight": "light", | |
| }, | |
| { | |
| "name": "Toy Car", | |
| "size": "medium", | |
| "clatters": "a bit", | |
| "weight": "medium", | |
| }, | |
| { | |
| "name": "Card Game", | |
| "size": "small", | |
| "clatters": "no", | |
| "weight": "light", | |
| }, | |
| ]; | |
| List<Map<String, dynamic>> presents = [ | |
| { | |
| "size": "medium", | |
| "clatters": "a bit", | |
| "weight": "medium", | |
| }, | |
| { | |
| "size": "small", | |
| "clatters": "yes", | |
| "weight": "light", | |
| }, | |
| ]; | |
| print(guestGifts(wishList, presents).toString()); | |
| } | |
| guestGifts(dynamic wishList, dynamic presents) { | |
| final result = presents.map((e) { | |
| return wishList.firstWhere( | |
| (element) => (element['size'].toString() == e['size'].toString() && | |
| element['clatters'].toString() == e['clatters'].toString() && | |
| element['weight'].toString() == e['weight'].toString()), | |
| )['name']; | |
| }).toList(); | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment