Skip to content

Instantly share code, notes, and snippets.

@g-alonso
Last active August 29, 2015 13:57
Show Gist options
  • Save g-alonso/9533726 to your computer and use it in GitHub Desktop.
Save g-alonso/9533726 to your computer and use it in GitHub Desktop.
Misc goes here...
//recursion
(function g(tree, element){
angular.forEach(tree, function(elm, k){
if(element.attribute_id == elm.attribute_id){
tree[k].repeated++;
}
g(tree[k].children, element);
});
})(scope.tree, element)
//---------------------------------------------------------------------
// Print the numbers from 1 to 10, 100ms apart. Or not.
for(var i = 0; i < 10; i++){
setTimeout(function(){
console.log(i+1);
}, 100*i);
}
/* To fix the bug, wrap the code in a self-executing function expression:
for(var i = 0; i < 10; i++){
(function(i){
setTimeout(function(){
console.log(i+1);
}, 100*i);
})(i);
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment