Skip to content

Instantly share code, notes, and snippets.

@fallengiants
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save fallengiants/7c91f9d7e79de13dd9b2 to your computer and use it in GitHub Desktop.

Select an option

Save fallengiants/7c91f9d7e79de13dd9b2 to your computer and use it in GitHub Desktop.
JSON Munging
// 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