Skip to content

Instantly share code, notes, and snippets.

@jabdul
Last active April 5, 2019 09:53
Show Gist options
  • Save jabdul/4b7e09f1da95bfdecabaffbb549f4632 to your computer and use it in GitHub Desktop.
Save jabdul/4b7e09f1da95bfdecabaffbb549f4632 to your computer and use it in GitHub Desktop.
Q1. Does Node.js support multi-processor platforms and how can we utilize all processor resources?
Q2. Write an event listener for the emitted customEvent and print to console the 'arg'
const EventEmitter = require('events');
class MyEmitter extends EventEmitter {
myFunc() {
this.emit('customEvent');
}
}
const arg = 'Craft Turf';
myEmitter.myFunc();
Q3. Rewrite the following asynchronous code using Promise
const fs = require('fs');
const readFileAsArray = function(file, cb) {
fs.readFile(file, function(err, data) {
if (err) {
return cb(err);
}
const lines = data.toString().trim().split('\n');
cb(null, lines);
});
};
Q4. Write test cases for the add function
const add = (a, b) => (a + b);
Q5. a) What's the value of a after 10 iterations
b) Are there any obvious issues with function foo?
function foo() {
function bar(a) {
i = 2;
console.log(a+i);
}
for (var i=0; i<10; i++) {
bar(i);
}
}
foo();
Q6. In mongodb, embedded data model is used when you have _________ relationships between entities
a) contains
b) isa
c) inheritance
d) all of the mentioned
Q7. Point out the wrong statement:
a) Embedded data models make it possible to update related data in a single atomic write operation
b) Embedding related data in documents may lead to situations where documents grow after creation
c) With the MMAPv1 storage engine, document growth can impact write performance and lead to data fragmentation
d) All of the mentioned
Q8. Describe reasons for when not to use Mongo DB?
Q9. MongoDB stores all documents in:
a) tables
b) collections
c) rows
d) all of the mentioned
Q10. Which of the following is a valid insert statement in mongodb? Select all valid.
a) db.test.insert({x:2,y:”apple”})
b) db.test.push({x:2,y:”apple”})
c) db.test.insert({“x”:2, “y”:”apple”})
d) db.test.insert({x:2},{y:”apple”})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment