Skip to content

Instantly share code, notes, and snippets.

@brandonvanha
Last active December 20, 2017 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonvanha/a2827490f97e5c180ac67c8cb061e3db to your computer and use it in GitHub Desktop.
Save brandonvanha/a2827490f97e5c180ac67c8cb061e3db to your computer and use it in GitHub Desktop.
// Return min or max key's value
// calendar_date is just an example placeholder.
// result.recordet is array of JSON Object.
var minNum = Math.min.apply( Math, result.recordset.map( function ( o ) { return o.calendar_date; } ) );
var maxNum = Math.max.apply( Math, result.recordset.map( function ( o ) { return o.calendar_date; } ) );
// Return entire JSON Object.
// calendar_date is just an example placeholder.
// result.recordet is array of JSON Object.
const min = result.recordset.reduce( function findMin( prev, current ) {
return ( prev.calendar_date < current.calendar_date ) ? prev : current;
} ); // return object.
const max = result.recordset.reduce( function findMax( prev, current ) {
return ( prev.calendar_date > current.calendar_date ) ? prev : current;
} ); // return object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment