Skip to content

Instantly share code, notes, and snippets.

@nicco88
Last active January 16, 2017 01:29
Show Gist options
  • Save nicco88/247e3d9155d59804db0d383d6c93a7bd to your computer and use it in GitHub Desktop.
Save nicco88/247e3d9155d59804db0d383d6c93a7bd to your computer and use it in GitHub Desktop.
// DRY code = don't repeat yourself
// WHILE LOOPS
// Repeat the code while the condition is true
while(someCondition) {
// run the code
}
// Printing n. from 1-5
var count = 1; // here we say where to start
while (count < 6 /* here we say where to finish*/) {
console.log("count is:" + count);
count++; // this is step length
}
// FUNCTIONS INSIDE FUNCTIONS
// RUN FUNCTION WITH DEBUGGER
function runWithDebugger(func) {
debugger;
func();
}
// SETTIMEOUT
setTimeout(function() {
console.log('ciao');
}, 5000)
// FOREACH
arr.forEach(function logName(name){
console.log(name);
})
// or
arr.forEach(logName)
// DIY forEach()
forEach(arr, myFunc) {
for(var i = 0; i < arr.length; i++) {
myFunc(arr[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment