Last active
February 7, 2017 22:05
-
-
Save xeaone/14f35a0ef782ab3e7bff6821d743f062 to your computer and use it in GitHub Desktop.
Loop through each an iterable and enables, break, continue, and manipulation.
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
function each (iterable, callback, scope) { | |
var statment = null, i = null, l = null, k = null; | |
if (iterable.constructor.name === 'Number') { | |
for (i = 0; i < iterable; i++) { | |
statment = callback.call(scope, i, iterable); | |
if (statment === 'break') break; | |
else if (statment === 'continue') continue; | |
} | |
} else if (iterable.constructor.name === 'Map') { | |
k = iterable.keys(); | |
for (i = 0, l = k.length; i < l; i++) { | |
statment = callback.call(scope, iterable.get(k[i]), k[i], iterable); | |
if (statment === 'break') break; | |
else if (statment === 'continue') continue; | |
} | |
} else if (iterable.constructor.name === 'Object') { | |
for (k in iterable) { | |
if (!iterable.hasOwnProperty(k)) continue; | |
statment = callback.call(scope, iterable[k], k, iterable); | |
if (statment === 'break') break; | |
else if (statment === 'continue') continue; | |
} | |
} else if (iterable.constructor.name === 'Array') { | |
for (i = 0, l = iterable.length; i < l; i++) { | |
statment = callback.call(scope, iterable[i], i, iterable); | |
if (statment === 'break') break; | |
else if (statment === 'continue') continue; | |
} | |
} | |
return iterable; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment