Last active
August 29, 2015 14:24
-
-
Save fallengiants/7c91f9d7e79de13dd9b2 to your computer and use it in GitHub Desktop.
JSON Munging
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
| // INPUT | |
| [ | |
| { "id": "a0001" | |
| , "name": "happiness inc." | |
| , "opens_at": (3600 * 8) | |
| , "closes_at": (3600 * 20) | |
| , "popularity": 8 | |
| } | |
| , | |
| { "id": "a0002" | |
| , "name": "Happiness Inc" | |
| , "opens_at": (3600 * 12) | |
| , "closes_at": (3600 * 22) | |
| , "popularity": 3 | |
| } | |
| , | |
| { "id": "a0003" | |
| , "name": "Space Planets" | |
| , "opens_at": (3600 * 5) | |
| , "closes_at": (3600 * 12) | |
| , "popularity": 10 | |
| } | |
| , | |
| { "id": "a0004" | |
| , "name": "A Generic Company" | |
| , "opens_at": (3600 * 10) | |
| , "closes_at": (3600 * 23) | |
| , "popularity": 1 | |
| } | |
| ] | |
| /* | |
| * -> sort by popularity, descending, using highest popularity for merged objects | |
| * -> merge names that are identical, ignoring case and nonword characters | |
| * -> list earliest opening hours and latest closing hours | |
| * -> eventually perhaps do split hours | |
| * -> display either name | |
| * -> link to all matching ids | |
| */ | |
| // --OUTPUT-- | |
| [ | |
| { "name": "Space Planets" | |
| , "opens_at": "5 AM" | |
| , "closes_at": "12 PM" | |
| , "links": ["http://example.com/a0003"] | |
| } | |
| , | |
| { "name": "Happiness Inc" | |
| , "opens_at": "8 AM" | |
| , "closes_at": "10 PM" | |
| , "links": ["http://example.com/a0001", "http://example.com/a0002"] | |
| } | |
| , | |
| { "name": "A Generic Company" | |
| , "opens_at": "10 AM" | |
| , "closes_at": "11 PM" | |
| , "links": ["http://example.com/a0004"] | |
| } | |
| ] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment