Last active
January 16, 2017 01:29
-
-
Save nicco88/247e3d9155d59804db0d383d6c93a7bd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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