Ссылки с подробными объяснениями:
drj11.wordpress.com/2009/04/02/python-iterating...
bayes.colorado.edu/PythonIdioms.html
SELECT t.tablename, pa.attname FROM pg_tables t JOIN pg_type pt ON pt.typname = t.tablename JOIN pg_attribute pa ON pa.attrelid = pt.typrelid WHERE t.tablename NOT LIKE 'pg\_%' AND t.tablename NOT LIKE 'sql\_%' AND attname NOT IN ('cmin', 'cmax', 'ctid', 'oid', 'tableoid', 'xmin', 'xmax');
var a = []; for (var i = 0; i < 10; a[i] = Math.round(Math.random() * 10), i++); console && console.log(a); function find(arr) { var currMin = Infinity; var currMinIndex = null; var maxDiff = -Infinity; var best = {}; for (var i in arr) { var v = a[i]; if (v < currMin) { currMin = v; currMinIndex = i; } if (v - currMin > maxDiff) { maxDiff = v - currMin; console && console.log('Now max diff from ' + v + ' and ' + currMin + ' is ' + maxDiff); best = {start: currMinIndex, stop: i, startValue : a[currMinIndex], stopValue : v}; } } return best; } var res = find(a); for (var i in res) { console && console.log(i + ': ' + res[i]); }