Promise.resolve([1,2,3])
.then(call('map', x =>2* x))
.then(console.log);//[ 2, 4, 6 ]
@@ -544,6 +544,8 @@ document.que
anagramsCached('javascript');// takes a long timeanagramsCached('javascript');// returns virtually instantly since it's now cached
console.log(anagramsCached.cache);// The cached anagrams map
+
negate
Negates a predicate function.
Take a predicate function and apply the not operator (!) to it with its arguments.
constnegate= func =>(...args)=> !func(...args);
+
[1,2,3,4,5,6].filter(negate(n => n %2==0));// [ 1, 3, 5 ]
once
Ensures a function is called only once.
Utilizing a closure, use a flag, called, and set it to true once the function is called for the first time, preventing it from being called again. In order to allow the function to have its this context changed (such as in an event listener), the function keyword must be used, and the supplied function must have the context applied. Allow the function to be supplied with an arbitrary number of arguments using the rest/spread (...) operator.
constonce= fn =>{let called =false;return function(...args) {
@@ -565,9 +567,6 @@ document.bodyawaitsleep(1000);
console.log('I woke up after 1 second.');
}
-
Logic
negate
Negates a predicate function.
Take a predicate function and apply the not operator (!) to it with its arguments.