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 775 times
Edit
1
Community Evaluations
developer avatar
Dwain
20/11/2023
Je ne savais pas que Pinppin = Peregrin Took
developer avatar
Auteur anonyme
28/04/2023
À peine le temps de lire la question.
developer avatar
Auteur anonyme
05/06/2023
Oui, je double le temps !
developer avatar
Auteur anonyme
26/05/2024
+1