Skip to content

Instantly share code, notes, and snippets.

@kamilogorek
Last active December 22, 2015 06:58
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 kamilogorek/6434504 to your computer and use it in GitHub Desktop.
Save kamilogorek/6434504 to your computer and use it in GitHub Desktop.
Sorting renditions ratio
<script type="text/javascript">
var fapiResponse = {{ albums[0].photos[0].images | json_encode | raw }};
var renditions = [];
var ratios = {};
for (key in fapiResponse) {
renditions.push(key.split('_retina')[0]);
}
renditions.map(function(rendition, i) {
var dimensions = rendition.split('x');
var ratio = Math.round(parseInt(dimensions[0], 10) / parseInt(dimensions[1], 10) * 1000) / 1000;
ratios[ratio] = {
ratio: ratio,
rendition: rendition
}
});
console.dir(ratios);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment