Hard
Considering the following ES2015 class:
class Hobbit {
static setRingOwner(to) {
Hobbit.ringOwner = to;
}
constructor(name) {
this.name = name;
}
giveRing(to) {
if (Hobbit.ringOwner !== this) {
return console.error(`Sorry ${this.name} but you do not have the ring.`);
}
Hobbit.setRingOwner(to);
}
}
And the following code
let bilbo = new Hobbit('Bilbo Baggins');
let frodo = new Hobbit('Frodo Baggins');
let sam = new Hobbit('Samwise Gamgee');
let merry = new Hobbit('Meriadoc Brandybuck');
let pippin = new Hobbit('Peregrin Took');
Hobbit.setRingOwner(bilbo);
bilbo.giveRing(frodo);
Hobbit.setRingOwner(sam);
sam.giveRing(bilbo);
frodo.giveRing(merry);
Hobbit.setRingOwner(pippin);
merry.giveRing(frodo);
At the execution end, whom of the 5 characters will be holding the ring ?
Author: Jean-marie CléryStatus: PublishedQuestion passed 775 times
Edit
Similar QuestionsMore questions about NodeJS
8
How to define a global variable with Node.js?4
Parse a query string into an object in NodeJS3
Which of these 4 solutions for serving a very large file will be the most optimized in terms of _server resources_ and _loading speed for the client_?3
A simple SocketIO chat server, coupled with Express.2
How to get the result of 3 asynchronous functions in NodeJS