Last active
January 10, 2022 16:23
-
-
Save funfunction/42918a4751ae51828cfc4c2dd4c0678e to your computer and use it in GitHub Desktop.
logForeachParam
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
/** | |
@func | |
with a supplied func and a supplied arr of args | |
- the func will invoke once for each arg in the arr | |
apply the func to each arg in the arr | |
@cons | |
this variant only supports funcs that are unary (argument count of one) | |
@param {(v: *) => *} fn - the func to be invoked for each elem in the arr | |
@param {*[]} a - each elem is passed as an arg to the func | |
*/ | |
export const logForeachParam = (fn, a) => { | |
console.log("\nlogForeachParam:", a.length, fn.name); | |
a.forEach(e => logFontBlueLight(fn(e))); | |
}; | |
//@tests | |
logForeachParam(Array.isArray, [1, 2, 3]); //false, false, false | |
logForeachParam(e => e + 1, [1, 2, 3]); // 2, 3, 4 | |
//util | |
export const logFontBlueLight = v => console.log("\u001b[36m", v, "\u001b[0m"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment