Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* 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] = /** **/ () => require(name); /** **/

});

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions

Question

8. Explain the relationship between communication and context.

Answered: 1 week ago