Last active
July 1, 2016 15:15
-
-
Save rikonor/cfaa84dbaae7c1a231643c1c33047e43 to your computer and use it in GitHub Desktop.
Javascript snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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