Question
* We will initialize the cache by iterating over all the built-in module * names. Specifically, for each built-in module name `name` we will set
* We will initialize the cache by iterating over all the built-in module
* names. Specifically, for each built-in module name `name` we will set
* `cache[name]` to a function which should return the corresponding module
* object. If the module has not already been loaded with require(), this
* function should do so. Importantly, however, it should only call require()
* once for any name. So, for example, the incorrect (but very close) solution
* is:
*
* cache[name] = () => require(name);
*
* The problem with this solution is that it calls require() every time
* getBuiltIn() is called. Nevertheless, if you're having trouble with this,
* you may wish to use this (incorrect solution) while you're working on the
* rest of the problem and get back to it later.
______________________________________________________________________________________
const cache = {};
exports._cache = cache;
function for_(cur, cond, next, fbody) {
return cond(cur) ? (fbody(cur), for_(next(cur), cond, next, fbody)) : undefined;
}
function isBuiltIn(name) {
let checker = false;
for_(0, i => i < names.size && !checker, i => i + 1, i => {
if (name === names.get(i)) {
checker = true;
}
});
return checker;
function each(list, f) {
if (list.size == 0) {
return;
}
//for_(0, i => i < list.length, i => i + 1, i => f(list[i], i));
for_(0, i => i < list.size, i => i + 1, i => f(list.get(i), i));
}
}
IMPLEMENT:
_.each(names, name => {
cache[name] = /**
});
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started