Question from the Node.js test

Given the following ES2015 class and code, who will be holding the ring at the end of the execution?

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 836 times
Edit
1
Community EvaluationsNo one has reviewed this question yet, be the first!