I've saved some uploaded images to various sizes, and would like to retrieve the smallest image possible, based on the browsers window size.
I created a "Rounder" class that you feed an array of integers into, and based on the number you feed an up, or down method, it will return the next nearest value. It just feels that im going about it in a mostly inefficient way. What do you think? jsfiddle: ------------ http://jsfiddle.net/G3j9D/1/ Class: ------------ var Rounder = new Class({ Implements: Options, options:{ steps: [] }, initialize: function(steps,options){ this.setOptions(options); this.steps = steps; }, up: function(integer){ var allOver = this.steps.filter(function(item){ return item > integer; }); return (allOver.length)? allOver[0]:Math.max.apply(Math,this.steps); }, down: function(integer){ var allUnder = this.steps.filter(function(item){ return item < integer; }); return allUnder[0]; } });
