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 936 times
Edit
1
Community EvaluationsNo one has reviewed this question yet, be the first!
3
How to get the result of 3 asynchronous functions in NodeJS3
A simple SocketIO chat server, coupled with Express.7
Parse a query string into an object in NodeJS3
Write a NodeJS server that returns a different message depending on the route.3
Which of the following is the odd one out? : npm, yeoman, webpack, babel4
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_?10
How to define a global variable with Node.js?