Skip to content

Instantly share code, notes, and snippets.

@rikonor
Last active July 1, 2016 15:15
Show Gist options
  • Save rikonor/cfaa84dbaae7c1a231643c1c33047e43 to your computer and use it in GitHub Desktop.
Save rikonor/cfaa84dbaae7c1a231643c1c33047e43 to your computer and use it in GitHub Desktop.
Javascript snippets
var myList = [10, -1, 20, -30, 40, 50, 60, 70, 80];
var findMinIndex = function(xs) {
return xs.reduce(function(currMinIdx, x, idx) {
return xs[idx] < xs[currMinIdx] ? idx : currMinIdx;
}, 0);
};
var minIndex = findMinIndex(myList);
console.log(minIndex);
var _ = require('lodash');
var a = {name: 'Or'};
var b = function() {
return {name: 'Laura'};
};
var stuff = {
a: a,
b: b,
};
_.forEach(stuff, function(v, k) {
if (typeof v === 'function') {
console.log('resolving', k);
stuff[k] = v();
}
});
console.log(stuff);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment