¡Te damos la bienvenida a este reto!

1

¡Bienvenido al mundo de JavaScript!

Día 1

2

Variables, funciones y sintaxis básica

3

Tipos de datos

4

Playground - Retorna el tipo

5

Tipos de datos - pt 2

Día 2

6

Operadores

7

Hoisting y coerción

8

Playground - Calcula la propina

9

Alcance de las variables

Día 3

10

Condicionales

11

Playground - Calcula años bisiestos

12

Switch

13

Playground - Obten información de mascotas según su tipo

14

Ciclos

15

Playground - Dibuja un triangulo

Día 4

16

Arrays

17

Playground - Encuentra al michi mas famoso

18

Objetos

19

Playground - Obten el promedio de los estudiantes

Día 5 - Checkpoint

20

Playground - encuentra el palindromo más grande

Día 6

21

Reasignación y redeclaración

22

Modo estricto

Día 7

23

Debugging y manejo de errores

24

Programación funcional

Quiz: Día 7

Día 8

25

Closures

26

Playground - Crea una calculadora con closures

27

Higher order functions

28

Playground - Crea tu propio método map

Día 9

29

ECMAScript

30

TC39

Quiz: Día 9

Día 10 - Checkpoint

31

ES6

32

ES7

33

Playground - Task planner

Día 11

34

Asincronismo

35

Playground - Promesas

36

Manejando el asincronismo

37

Playground - Resuelve el callback hell usando promesas

38

Playground - Resuelve el callback hell usando async/await

Día 12

39

Arrays a profundidad

40

Métodos de arrays: Every, Find y findIndex

41

Playground - Válida el formulario

Día 13

42

Métodos de arrays: Includes, Join y concat

43

Playground - agrupa los productos

44

Métodos de arrays: Flat y FlatMap

45

Playground - Encuentra la ubicación del valor buscado

Día 14

46

Mutable functions

47

Playground - Modifica una lista de compras

48

Métodos de arrays: sort

49

Playground - Ordena los productos

Día 15 - Checkpoint

50

Playground - Sistema de reservaciones de un hotel

Día 16

51

Programación orientada a objetos en JavaScript

52

Objetos literales

53

Playground - Congela el objeto recursivamente

Día 17

54

Prototipos en JavaScript

55

Playground - Modifica el prototype de los arrays

56

Playground - Crea un auto usando clases

Día 18

57

Abstracción en JavaScript

58

Playground - Sistema de carrito de compras

59

Encapsulamiento en JavaScript

60

Playground - Encapsula datos de los usuarios

Día 19

61

Herencia en JavaScript

62

Playground - Jerarquía de animales

63

Polimorfismo en JavaScript

64

Playground - Sistema de pagos

Día 20 - Checkpoint

65

Playground - Agenda de vuelos

Día 21

66

Patrones de diseño

67

Sinlgeton y Factory pattern en JavaScript

68

Playground - Implementa singleton en un chat

Día 22

69

Adapter y Decorator pattern en JavaScript

70

Playground - Personaliza productos de una tienda

71

Builder y Protype pattern en JavaScript

72

Playground - Mejora el código usando builder pattern

Día 23

73

Facade y proxy pattern en JavaScript

74

Playground - Proxy en servicio de mensajería

75

Chain of responsability y Observer pattern en JavaScript

76

Playground - Implementación de Observador en Newsletter

Día 24 - Checkpoint

77

Playground - Crea un task manager con patrones de diseño

Día 25

78

Estructuras de datos en JavaScript

79

Playground - Crea tu propia implementación de un array

80

Hash tables en JavaScript

81

Playground - Implementación de una HashTable para Contactos

Día 26

82

Set en JavaScript

83

Playground - Remueve duplicados de una lista

84

Maps en JavaScript

85

Playground - Crea un organizador de tareas

Día 27

86

Singly Linked List en JavaScript

87

Playground - Agrega métodos a la singly linked list

88

Playground - Implementación de una singly linked list

Día 28

89

Stacks en JavaScript

90

Playground - Crea un stack para una playlist

Día 29

91

Queues en JavaScript

92

Playground - Crea una cola de emails

Día 30

93

¡Lo lograste!

Live Class

94

30 días de JS con Juan DC

95

30 días de JS con Nicobytes

96

30 días de JS con GNDX

97

30 días de JS con LeoCode

98

30 días de JS con Teffcode

99

Sesión: Cierre de los 30 días de JavaScript

No tienes acceso a esta clase

¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera

Playground - Implementación de una singly linked list

88/99

Aportes 21

Preguntas 0

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad?

Listo.

Node.js

export class Node {
  constructor(name, age, bedNumber) {
    this.name = name;
    this.age = age;
    this.bedNumber = bedNumber;
    this.next = null;
  }
}

exercise.js

import { Node } from "./Node";

export class PatientList {
  constructor(beds) {
    this.head = null;
    this.tail = null;
    this.length = 0;
    this.beds = this.arrayFrom(beds);
  }

  arrayFrom(tamanio) {
    let array = [];
    for (let x = 1; x <= tamanio; x++) {
      array.push({ bed: x, available: true });
    }
    return array;
  }

  addPatient(name, age) {
    let bedAvailable = this.beds.findIndex(bed => bed.available === true);
    console.log('Cama asignada numero: ' + this.beds[bedAvailable].bed);
    if (bedAvailable >= 0) {
      let newNode = new Node(name, age, this.beds[bedAvailable].bed);
      if (!this.head) {
        this.head = newNode;
        this.tail = newNode;
      } else {
        this.tail.next = newNode;
        this.tail = newNode;
        this.length++;
      }
      this.beds[bedAvailable].available = false;
      return;
    }
    throw Error("No hay camas disponibles");
  }

  removePatient(name) {
    if (!this.head) {
      return null;
    }
    if (this.head.name === name) {
      let bedAvailable = this.beds.findIndex(bed => bed.bed === this.head.bedNumber);
      this.beds[bedAvailable].available = true;
      this.head = this.head.next;
      this.length--;
      return;
    }
    let currentNode = this.head;
    while (currentNode.next) {
      if (currentNode.next.name === name) {
        let bedAvailable = this.beds.findIndex(bed => bed.bed === currentNode.next.bedNumber);
        this.beds[bedAvailable].available = true;
        currentNode.next = currentNode.next.next;
        this.length--;
        return;
      }
      currentNode = currentNode.next;
    }
    throw Error("Paciente no encontrado");
  }

  getPatient(name) {
    let currentNode = this.head;
    while (currentNode.next) {
      if (currentNode.name === name) {
        return {name: currentNode.name, age: currentNode.age, bedNumber: currentNode.bedNumber};
      }
      throw Error("Paciente no encontrado");
    }
  }

  getPatientList() {
    let currentNode = this.head;
    let patients = [];
    while (currentNode) {
      patients.push({ name: currentNode.name, age: currentNode.age, bedNumber: currentNode.bedNumber });
      currentNode = currentNode.next;
    }
    return patients;
  }

  getAvailableBeds() {
    let counter = 0;
    this.beds.map(bed => {
      if (bed.available === true) {
        counter++;
      }
    });
    return counter;
  }
}

![](https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExcW9vZG10dTdzaHBmMnpvb2xqNXA3bWd6c29jbnp3azcybjJ2eDk1cSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/VIPdgcooFJHtC/giphy.gif) ![](https://static.platzi.com/media/user_upload/code-75f14717-dde5-45dc-bd86-2edb7811d95c.jpg)

🛡️🛡️Escudo anti-spoilers🛡️🛡️

Mi solución al reto:

Mencionar que mi código funcionaba perfecto en la vista, pero no podía pasar la ultima prueba: "should assign a bed with the correct number after delete other patient"
ya que esta prueba esperaba que la lista de camas se “desordenara”, es decir, mi código mantenía la ‘singly linked list’ ordenada por numero de cama como 1,2 3, (manera ascendente) independientemente si se agregaban o quitaban pacientes.

Así que para cumplir con esa validación (que para mi punto de vista está de más) tuve que agregar un método ‘_updateOrder()’ y una propiedad llamada ‘order’, para poder hacer un sort y entregar la lista con el numero de camas ordenadas como la prueba lo esperada (2,3,1) donde la 1 fue la ultima que cambió de paciente… anyway, here my code:

import { Node } from "./Node.js";

export class PatientList {
  constructor(beds) {
    let lastNode, currentNode = null
    this.order = 0;
    for (let e = 0; e < beds; e++) {
      currentNode = new Node(null, null, e + 1)
      currentNode.order = this._updateOrder()
      if (e === 0) this.head = currentNode
      if (lastNode) lastNode.next = currentNode
      lastNode = currentNode
    }
    this.tail = currentNode
  }

  _updateOrder() {
    this.order++
    return this.order
  }

  addPatient(name, age) {
    let cN = this.head
    while (cN) {
      if (!cN.name) {
        cN.name = name
        cN.age = age
        cN.order = this._updateOrder()
        return
      }
      cN = cN.next
    }
    throw new Error("No hay camas disponibles")
  }

  removePatient(name) {
    let cN = this.head
    while (cN) {
      if (cN.name === name) {
        cN.name = null
        cN.age = null
        cN.order = this._updateOrder()
        return
      }
      cN = cN.next
    }
    throw new Error("Paciente no encontrado")
  }

  getPatient(name) {
    let cN = this.head
    let patient = {}
    while (cN) {
      if (cN.name === name) {
        patient = { name: cN.name, age: cN.age, bedNumber: cN.bedNumber }
        return patient
      }
      cN = cN.next
    }
    throw new Error("Paciente no encontrado")
  }

  getPatientList() {
    let cN = this.head
    let list = []
    while (cN) {
      if (cN.name) {
        list.push({
          name: cN.name,
          age: cN.age,
          bedNumber: cN.bedNumber,
          order: cN.order
        })
      }
      cN = cN.next
    }
    return list.sort((a, b) => a.order - b.order).map(i => {
      delete i.order;
      return i;
    })

  }

  getAvailableBeds() {
    let cN = this.head
    let totalAvailBeds = 0;
    while (cN) {
      if (!cN.name) totalAvailBeds++;
      cN = cN.next
    }
    return totalAvailBeds
  }
}

Hola, La solución con la ayuda de los comentarios


















Node.js

export class Node {
  constructor(name, age, bedNumber) {
    this.name = name;
    this.age = age;
    this.bedNumber = bedNumber;
    this.next = null;
  }
}

exercise.js

import { Node } from "./Node";

export class PatientList {
  constructor(beds) {
    this.head = null;
    this.tail = null;
    this.bedsAvailable = Array.from({ length: beds });
    for (let i = 0; i < beds; i++) {
      this.bedsAvailable[i] = i + 1;
    }
  }

  addPatient(name, age) {
    if (this.bedsAvailable.length === 0) {
      throw new Error("No hay camas disponibles");
    }

    const newPatient = new Node(name, age, this.bedsAvailable[0]);
    this.bedsAvailable.shift();

    if (!this.head) {
      this.head = newPatient;
      this.tail = newPatient;
    } else {
      this.tail.next = newPatient;
      this.tail = newPatient;
    }
  }

  removePatient(name) {
    if (!this.head) {
      throw new Error("Paciente no encontrado");
    }
    let current = this.head;
    let prev = null;

    while (current) {
      if (current.name === name) {
        if (!prev) {
          this.head = current.next;
        } else {
          prev.next = current.next;
        }

        this.bedsAvailable.push(current.bedNumber);
        return;
      }

      prev = current;
      current = current.next;
    }

    throw new Error("Paciente no encontrado");
  }

  getPatient(name) {
    let current = this.head;

    while (current) {
      if (current.name === name) {
        return {
          name: current.name,
          age: current.age,
          bedNumber: current.bedNumber,
        };
      }

      current = current.next;
    }

    throw new Error("Paciente no encontrado");
  }

  getPatientList() {
    const patients = [];
    let current = this.head;

    while (current) {
      patients.push({
        name: current.name,
        age: current.age,
        bedNumber: current.bedNumber,
      });

      current = current.next;
    }

    return patients;
  }

  getAvailableBeds() {
    return this.bedsAvailable.length;
  }
}

Aqui esta mi solución. Este tema de singly linked list es un poco abstracto pero creo que llegué a una solución sencilla de entender:
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Node.js

export class Node {
  constructor(name, age, bedNumber) {
    // Tu código aquí 👈🏻
    this.name = name;
    this.age = age;
    this.bedNumber = bedNumber;
    this.next = null;
  }
}

exercise.js

import { Node } from "./Node";

export class PatientList {
  constructor(beds) {
    // Tu código aquí 👈🏻
    this.head = null;
    this.tail = null;
    this.length = 0;
    this.beds = new Array();
    for(let i = 1; i <= beds; i++){
        this.beds.push(i);
    }
  }

  addPatient(name, age) {
    // Tu código aquí 👈🏻
    if(this.beds.length === 0) throw new Error("No hay camas disponibles");

    const newPatient = new Node(name, age, this.beds[0]);
    this.beds.shift();

    if(!this.head){
        this.head = newPatient;
        this.tail = newPatient;
    }
    else{
        this.tail.next = newPatient;
        this.tail = newPatient;
    }
    this.length++;
  }

  removePatient(name) {
    // Tu código aquí 👈🏻
    if(!this.head) throw new Error("Paciente no encontrado");

    if(this.head.name === name){
        this.beds.push(this.head.bedNumber);
        this.head = this.head.next;
        this.length--;
        return;
    }

    let currentNode = this.head;

    while(currentNode.next){
        if(currentNode.next.name === name){
            this.beds.push(currentNode.next.bedNumber);
            currentNode.next = currentNode.next.next;
            this.length--;
            return;
        }
        currentNode = currentNode.next;
    }

    throw new Error("Paciente no encontrado");
  }

  getPatient(name) {
    // Tu código aquí 👈🏻
    if(!this.head) throw new Error("Paciente no encontrado");

    let currentNode = this.head;

    while(currentNode){
        if(currentNode.name === name){
            return{
                name: currentNode.name,
                age: currentNode.age,
                bedNumber: currentNode.bedNumber
            }
        }
        currentNode = currentNode.next;
    }

    throw new Error("Paciente no encontrado");
  }

  getPatientList() {
    // Tu código aquí 👈🏻
    const list = new Array();

    let currentNode = this.head;

    while(currentNode){
        list.push({
            name: currentNode.name,
            age: currentNode.age,
            bedNumber: currentNode.bedNumber
        })
        currentNode = currentNode.next;
    }

    return list;
  }

  getAvailableBeds() {
    // Tu código aquí 👈🏻
    return this.beds.length;
  }
}

Mi aporte 🧐

export class Node {
  constructor(name, age, bedNumber) {
    this.name = name
    this.age = age
    this.bedNumber = bedNumber
    this.next = null
  }
}
import { Node } from "./Node";

export class PatientList {
  constructor(beds) {
    this.beds = beds
    this.head = null
    this.tail = null
    this.lenght = 0

    PatientList.splitedBeds = []
    PatientList.allBeds = []
    for (let i = 1; i <= this.beds; i++) PatientList.splitedBeds.push(i)

    for (let i = 0; i <= PatientList.splitedBeds.length - 1; i++) {
      PatientList.allBeds.push({ bed: PatientList.splitedBeds[i], isAviable: true })
    }
  }

  addPatient(name, age) {


    let bedToAssingn = () => {
      return PatientList.allBeds.find(aviableBed => {
        if (aviableBed.isAviable === true) {
          aviableBed.isAviable = false
          return aviableBed
        }
        else if (this.beds === 0) throw new Error('No hay suficientes camas')
      }
      )
    }
    const newNode = new Node(name, age, bedToAssingn().bed)
    this.beds--

    if (!this.head) {
      this.head = newNode
      this.tail = newNode
    }
    else {
      this.tail.next = newNode
      this.tail = newNode
    }
    this.lenght++
  }
  lookingForDelete(name) {
    let currentPatient = this.head
    let previousNode = null
    while (currentPatient.next) {
      if (currentPatient.next.name === name) {
        currentPatient.next = currentPatient.next.next
        this.lenght--
        this.beds++
        return previousNode
      }
      currentPatient = currentPatient.next
      previousNode = currentPatient
    }
  }
  removePatient(name) {
    let removed = null
    if (!this.head) {
      throw new Error('lista vacia')
    }
    else if (this.head.name === name) {
      removed = this.head
      this.head = this.head.next
      this.lenght--
      this.beds++
    }
    else if (this.tail.name === name) {
      removed = this.tail
      this.tail = this.lookingForDelete(name)
    }
    else {
      this.lookingForDelete(name)
    }

    if (removed === null) {
      throw new Error("Paciente no encontrado")
    }
    else {
      PatientList.allBeds.find(bed => removed.bedNumber === bed.bed ? bed.isAviable = true : false)
    }
  }
  lookingForReturn(name) {

  }
  getPatient(name) {
    let currentPatient = this.head
    let patient = null
    if (!this.head) {
      throw new Error('lista vacia')
    }
    else if (this.head.name === name) {
      patient = { name: this.head.name, age: this.head.age, bedNumber: this.head.bedNumber }
    }
    else if (this.tail.name === name) {
      patient = { name: this.tail.name, age: this.tail.age, bedNumber: this.tail.bedNumber }
    }
    else {
      while (currentPatient.next) {
        if (currentPatient.name === name) {
          patient = { name: currentPatient.name, age: currentPatient.age, bedNumber: currentPatient.bedNumber }
        }
        currentPatient = currentPatient.next
      }
    }
    if (patient === null) {
      throw new Error("Paciente no encontrado")
    }
    else {

      return patient
    }
  }

  getPatientList() {
    let allPatients = []
    let currentPatient = this.head
    for (let i = 0; i < this.lenght; i++) {
      allPatients.push({ name: currentPatient.name, age: currentPatient.age, bedNumber: currentPatient.bedNumber })
      currentPatient = currentPatient.next
    }
    return allPatients
  }

  getAvailableBeds() {
    return this.beds
  }
}

Pues yo tengo mi solución aunque mi lista nunca se desordena y asigna al paciente a la prime cama disponible de la lista y nunca la desordena, porque así como no se pueden mover los pacientes de camas, las camas tampoco deberías de moverlas de sus lugares, creo que es mas lógico
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

exercise.js

import { Node } from "./Node";

export class PatientList {
  constructor(beds) {
    // Tu código aquí 👈🏻
    this.beds = beds;
    this.firstBed = null;
    this.lastBed = null;
    for (let i = 1; i <= this.beds; i++) {
      const newBed = new Node('', 0, i);
      if (!this.firstBed) {
        this.firstBed = newBed;
        this.lastBed = newBed;
      } else {
        this.lastBed.next = newBed;
        this.lastBed = newBed;
      }
    }
  }

  addPatient(name, age) {
    // Tu código aquí 👈🏻
    let cNode = this.firstBed;
    for (let i = 1; i <= this.beds; i++) {
      if (cNode.available) {
        cNode.name = name;
        cNode.age = age;
        cNode.available = false;
        return;
      }
      cNode = cNode.next;
    }
    throw new Error('No hay camas disponibles');
  }

  removePatient(name) {
    // Tu código aquí 👈🏻
    let cNode = this.firstBed;
    for (let i = 1; i <= this.beds; i++) {
      if (cNode.name === name) {
        cNode.name = '';
        cNode.age = 0;
        cNode.available = true;
        return;
      }
      cNode = cNode.next;
    }
    throw new Error('Paciente no encontrado');
  }

  getPatient(name) {
    // Tu código aquí 👈🏻
    let cNode = this.firstBed;
    for (let i = 1; i <= this.beds; i++) {
      if (cNode.name === name) {
        const { name, age, bedNumber } = cNode;
        return { name, age, bedNumber };
      }
      cNode = cNode.next;
    }
    throw new Error('Paciente no encontrado');
  }

  getPatientList() {
    // Tu código aquí 👈🏻
    let listPatients = []
    let cNode = this.firstBed;
    for (let i = 1; i <= this.beds; i++) {
      if (!cNode.available) {
        const { name, age, bedNumber } = cNode;
        listPatients.push({ name, age, bedNumber })
      }
      cNode = cNode.next;
    }
    return listPatients;
  }

  getAvailableBeds() {
    // Tu código aquí 👈🏻
    let bedsAvailable = 0;
    let cNode = this.firstBed;
    for (let i = 1; i <= this.beds; i++) {
      if (cNode.available) {
        bedsAvailable++;
      }
      cNode = cNode.next;
    }
    return bedsAvailable;
  }
}

node.js

export class Node {
  constructor(name, age, bedNumber) {
    // Tu código aquí 👈🏻
    this.name = name;
    this.age = age;
    this.bedNumber = bedNumber;
    this.available = true;
    this.next = null;
  }
}

Aquí mi solución:
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Node.js

export class Node {
  constructor(name, age, bedNumber) {
    this.name = name;
    this.age = age;
    this.bedNumber = bedNumber;
  }
}

exercise.js

import { Node } from "./Node";

export class PatientList {
  constructor(beds) {
    this.head = null;
    this.tail = null;
    this.length = 0;
    this.bed = [];
    for (let ii = 1; ii <= beds; ii++) {
      this.bed.push({ bedNumber: ii, available: false })
    }
  }

  addPatient(name, age) {
    let bed = this.bed.find(item => item.available === false);
    if (bed) {
      const newNode = new Node(name, age, bed.bedNumber);
      if (!this.head) {
        this.head = newNode;
        this.tail = newNode;
      } else {
        this.tail.next = newNode;
        this.tail = newNode;
      }
      bed.available = true;
      this.length++;

    } else {
      throw new Error("No hay camas disponibles");
    }
  }

  removePatient(name) {
    if (this.head) {
      let bedNumber;
      if (this.head.name === name) {
        bedNumber = this.head.bedNumber;
        let bed = this.bed.find(item => item.bedNumber === bedNumber);
        if (bed) { bed.available = false; }
        this.head = this.head.next;
        this.length--;
        return;
      }
      let currentNode = this.head;
      while (currentNode.next) {
        if (currentNode.next.name === name) {
          bedNumber = currentNode.next.bedNumber;
          let bed = this.bed.find(item => item.bedNumber === bedNumber);
          if (bed) { bed.available = false; }
          currentNode.next = currentNode.next.next;
          this.length--;
          return;
        }
        currentNode = currentNode.next;
      }
    }
    throw new Error("Paciente no encontrado");
  }

  getPatient(name) {
    if (this.head) {
      let currentNode = this.head;
      if (currentNode.name === name) {
        return { name: currentNode.name, age: currentNode.age, bedNumber: currentNode.bedNumber }
      }
      while (currentNode.next) {
        if (currentNode.next.name === name) {
          return { name: currentNode.next.name, age: currentNode.next.age, bedNumber: currentNode.next.bedNumber }
        }
        currentNode = currentNode.next;
      }
    }
    throw new Error("Paciente no encontrado");
  }

  getPatientList() {
    let list = [];
    if (!this.head || this.length <= 0) {
      throw new Error("No hay pacientes registrados")
    }
    let currentNode = this.head;
    list.push({ name: currentNode.name, age: currentNode.age, bedNumber: currentNode.bedNumber })

    while (currentNode.next) {
      list.push({ name: currentNode.next.name, age: currentNode.next.age, bedNumber: currentNode.next.bedNumber });
      currentNode = currentNode.next;
    }

    return list;
  }

  getAvailableBeds() {
    debugger
    if (!this.head || this.length <= 0) {
      throw new Error("No hay camas registradas")
    }
    let beds = this.bed.filter(item => item.available === false)
    if (beds) {
      return beds.length;
    }
  }
}

Solucion

Me apoyé en la solución de Gregorio Navarrete (gracias).
+
+
+
+
+
+
+
+

export class Patient {
  constructor(name, age) {
    // Tu código aquí 👈🏻
    this.name = name;
    this.age = age;
    this.bedNumber = null;
    this.next = null;
  }
}

class PatientList {
  constructor(beds) {
    // Tu código aquí 👈🏻
    this.head = null;
    this.tail = null;
    this.length = 0;
    this.beds = Array(beds).fill(true);
  }

  addPatient(name, age) {
    // Tu código aquí 👈🏻
    if (this.length === this.beds.length) return "No free beds";

    const freeBed = this.beds.findIndex((bed) => bed);
    this.beds[freeBed] = false;

    const newPatient = new Patient(name, age);
    newPatient.bedNumber = freeBed + 1;

    if (!this.head) {
      this.head = newPatient;
      this.tail = newPatient;
    } else {
      this.tail.next = newPatient;
      this.tail = newPatient;
    }
    this.length++;
  }

  removePatient(name) {
    // Tu código aquí 👈🏻
    if (!this.head) return null;

    let current = this.head;
    let prev = null;
    while (current) {
      if (name === current.name) {
        if (current === this.head) {
          this.beds[current.bedNumber - 1] = true;
          this.head = this.head.next;
        } else if (current === this.tail) {
          this.beds[current.bedNumber - 1] = true;
          this.tail = prev;
          prev.next = null;
        } else {
          prev.next = current.next;
        }
        this.length--;
        return current;
      }
      prev = current;
      current = current.next;
    }
    return null;
  }

  getPatient(name) {
    // Tu código aquí 👈🏻
    if (!this.head) {
      throw Error("No patients at the hospital");
    }

    // Check head & tail values
    if (this.head.name === name) {
      let { name, age, bedNumber } = this.head;
      return { name, age, bedNumber };
    }

    if (this.tail.name === name) {
      let { name, age, bedNumber } = this.tail;
      return { name, age, bedNumber };
    }

    let currentPatient = this.head.next;

    while (currentPatient) {
      if (currentPatient.name === name) {
        let { name, age, bedNumber } = currentPatient;
        return { name, age, bedNumber };
      }
      currentPatient = currentPatient.next;
    }

    throw Error(`Patient ${name}, not found!`);
  }

  getPatientList() {
    // Tu código aquí 👈🏻
    let array = [];
    let currentPatient = this.head;
    while (currentPatient) {
      const patientData = {
        name: currentPatient.name,
        age: currentPatient.age,
        bedNumber: currentPatient.bedNumber,
      };
      array.push(patientData);
      currentPatient = currentPatient.next;
    }
    return array;
  }

  getAvailableBeds() {
    // Tu código aquí 👈🏻
    return `Beds available: ${this.length - this.beds.length}`;
  }
}

Node.js

export class Node {
  constructor(name, age, bedNumber) {
    this.name = name;
    this.age = age;
    this.bedNumber = bedNumber;
    this.next = null;
  }
  toString() { 
    return { name: this.name, age: this.age, bedNumber: this.bedNumber };
  }
}

exercise.js

import { Node } from "./Node";

export class PatientList {
  constructor(beds) {
    this.maxBeds = beds;
    this.head = null;
    this.tail = null;
    this.length = 0;
    this.availableBeds = [];
    for (let i = beds; i > 0; i--){
      this.availableBeds.push(i);
    }
  }

  addPatient(name, age) {
    if (this.length >= this.maxBeds) {
      throw new Error("No hay camas disponibles");
    }
    const newNode = new Node(name, age, this.availableBeds.pop());
    if (!this.head) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      this.tail = newNode;

    }
    this.length++
  }

  removePatient(name) {
    if (!this.head || !name) {
      throw new Error("Paciente no encontrado");
    }

    if (this.head.name === name) {
      this.availableBeds.push(this.head.bedNumber);
      this.head = this.head.next;
      this.length--;
      return;
    }

    let node = this.head;
    while (node.next) {
      if (node.next.name === name) {
        this.availableBeds.push(node.next.bedNumber);
        node.next = node.next.next;
        if (!node.next) {
          this.tail = node;
        }

        this.length--;
        return;
      }
      node = node.next;
    }
    throw new Error("Paciente no encontrado");
  }

  getPatient(name) {
    if (!this.head || !name) {
      throw new Error("Paciente no encontrado");
    }

    if (this.head.name === name) {
      return this.head.toString();
    }

    let node = this.head;
    while (node.next) {
      node = node.next;
      if (node.name === name) {
        return node.toString(); 
      }
    }

    throw new Error("Paciente no encontrado");
  }

  getPatientList() {
    if (!this.head) {
      return null;
    }
    const array = [];
    array.push(this.head.toString());
    let currentNode = this.head;
    while (currentNode.next) {
      array.push(currentNode.next.toString());
      currentNode = currentNode.next;
    }
    return array;
  }

  getAvailableBeds() {
    return this.maxBeds - this.length;
  }
}

MI SOLUCION 💪
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
class Node

export class Node {
  constructor(name, age, bedNumber) {
    this.name = name;
    this.age = age;
    this.bedNumber = bedNumber;
    this.next = null;
  }
}

class PatientList

import { Node } from "./Node";

export class PatientList {
  constructor(beds) {
    this.head = null;
    this.tail = null;
    this.length = 0;
    this.beds = new Array(beds).fill("available");
  }

  addPatient(name, age) {
    if (this.getAvailableBeds() === 0) throw new Error("No hay camas disponibles");
    const index = this.beds.indexOf("available");
    this.beds[index] = "notAvailable";
    const newNode = new Node(name, age, index + 1);
    if (!this.head) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      this.tail = newNode;
    }
    this.length++;
  }

  removePatient(name) {
    if (!this.head) {
      return null;
    }
    if (this.head.name === name) {
      this.beds[0] = "available";
      this.head = this.head.next;
      this.length--;
      return;
    }
    let currentNode = this.head;
    while (currentNode.next) {
      if (currentNode.next.name === name) {
        this.beds[currentNode.bedNumber - 1] = "available";
        currentNode.next = currentNode.next.next;
        this.length--;
        return;
      }
      currentNode = currentNode.next;
    }
    throw new Error("Paciente no encontrado");
  }

  getPatient(name) {
    let currentNode = this.head;
    while (currentNode) {
      if (currentNode.name === name) {
        return {
          name: currentNode.name,
          age: currentNode.age,
          bedNumber: currentNode.bedNumber
        };
      }
      currentNode = currentNode.next;
    }
    throw new Error("Paciente no encontrado");
  }

  getPatientList() {
    const values = [];
    let currentNode = this.head;
    for (let i = 0; i < this.length; i++) {
      values.push({
        name: currentNode.name,
        age: currentNode.age,
        bedNumber: currentNode.bedNumber
      });
      currentNode = currentNode.next;
    }
    return values;
  }

  getAvailableBeds() {
    return this.beds.reduce((acum, bed) => {
      if (bed === "available") acum++;
      return acum;
    },0);
  }
}

Solución… 😄
.
Siento que me compliqué demasiado 😅… fue muy entretenido el reto.
.
No entendí bien el “agrega un nuevo paciente a la lista, asignándole la próxima cama disponible”. Hice una lista ordenada de camas donde marcaba las camas como disponible y no disponible, y asignaba el paciente a la primera cama disponible.
.
Adjunto la solución del playground y la lista anteriormente mencionada que me parece una mejora interesante del reto.
.

.
Node.js:

export class Node{
  constructor(name, age, bedNumber){
    this.name = name
    this.age = age 
    this.bedNumber = bedNumber
    this.next = null
  }
}

.
exercise.js:

import { Node } from "./Node";

export class PatientList {
  constructor(beds) {
    this.head = null;
    this.tail = null;
    this.availableBeds = Array.from(
      { length: beds },
      (_, i) => i + 1);
  }

  addPatient(name, age) {
    if (this.availableBeds.length === 0) {
      throw new Error("No hay camas disponibles");
    }

    const newPatient = new Node(
      name, age, this.availableBeds[0]
    );
    this.availableBeds.shift();

    if (!this.head) {
      this.head = newPatient;
      this.tail = newPatient;
    }

    this.tail.next = newPatient;
    this.tail = newPatient;
  }

  removePatient(name) {
    if (!this.head) {
      throw new Error("Paciente no encontrado");
    }
    
    let actual = this.head;
    let previous = null;

    while (actual) {
      if (actual.name === name) {
        if (!previous) {
          this.head = actual.next;
        } else {
          previous.next = actual.next;
        }

        this.availableBeds.push(actual.bedNumber);
        return;
      }

      previous = actual;
      actual = actual.next;
    }

    throw new Error("Paciente no encontrado");
  }

  getPatient(name) {
    let actual = this.head;

    while (actual) {
      if (actual.name === name) {
        return {
          name: actual.name,
          age: actual.age,
          bedNumber: actual.bedNumber,
        };
      }

      actual = actual.next;
    }

    throw new Error("Paciente no encontrado");
  }

  getPatientList() {
    const patients = [];
    let actual = this.head;

    while (actual) {
      patients.push({
        name: actual.name,
        age: actual.age,
        bedNumber: actual.bedNumber,
      });

      actual = actual.next;
    }

    return patients;
  }

  getAvailableBeds() {
    return this.availableBeds.length;
  }
}

.
Lista mejorada:

import { Node } from "./Node";

export class PatientList {
  constructor(beds) {
    this.beds = beds;
    this.head = null;
    this.tail = null;
    this.length = 0;
    this.bedList = this.initBeds();
    this.nextAvailableBed = this.findAvailableBed();
  }

  initBeds() {
    let allBeds = [];

    for (let i = 1; i <= this.beds; i++) {
      allBeds.push({
        number: i,
        available: true
      });
    }

    return allBeds;
  }

  findAvailableBed() {
    return this.bedList.find(
      bed => bed.available
    )?.number || undefined;
  }

  markBed() {
    this.bedList.forEach(bed => {
      if (bed.number === this.nextAvailableBed) {
        bed.available = false;
      }
    });

    this.length++;
    this.nextAvailableBed = this.findAvailableBed();
  }

  unmarkBed(num) {
    this.bedList.forEach(bed => {
      if (bed.number === num) {
        bed.available = true;
      }
    });

    this.length--;
    this.nextAvailableBed = this.findAvailableBed();
  }

  addPatient(name, age) {
    if (!this.nextAvailableBed) {
      throw new Error("No hay camas disponibles");
    }

    let newPatient = new Node(
      name, age, this.nextAvailableBed
    );

    if (!this.head) {
      this.head = newPatient;
      this.tail = newPatient;
      this.markBed();
      return this;
    }

    let actual = this.head;
    while (actual.next) {
      if (actual.next.bedNumber > this.nextAvailableBed) {
        newPatient.next = actual.next;
        actual.next = newPatient;
        this.markBed();
        return this;
      }

      actual = actual.next;
    }

    actual.next = newPatient;
    this.tail = actual.next;
    this.markBed();
  }

  removePatient(name) {
    if (!this.head) { 
      return null;
    }

    if (this.head.name === name) {
      this.unmarkBed(this.head.bedNumber)
      this.head = this.head.next;
      return this;
    }

    let actual = this.head;

    while (actual.next) { 
      if (actual.next.name === name) {
        if (!actual.next.next) {
          this.unmarkBed(actual.next.bedNumber);
          this.tail = actual;
          actual.next = null;
          return this;
        }
        this.unmarkBed(actual.next.bedNumber);
        actual.next = actual.next.next;
        return this;
      }
      actual = actual.next;
    }

    throw new Error("Paciente no encontrado");
  }

  getPatient(name) {
    let actual = this.head;

    while (actual) {
      if (actual.name === name) { 
        return {
          name: actual.name,
          age: actual.age,
          bedNumber: actual.bedNumber
        };
      }

      actual = actual.next;
    }

    throw new Error("Paciente no encontrado");
  }

  getPatientList() {
    let actual = this.head;
    let list = [];

    while (actual) {
      list.push({
        name: actual.name,
        age: actual.age,
        bedNumber: actual.bedNumber
      });

      actual = actual.next;
    }

    return list;
  }

  getAvailableBeds() {
    return this.bedList.filter(bed => bed.available).length;
  }
}
Es un ejercicio muy bueno, y su estructura de datos se puede usar en muchos casos diferentes como "gestionar datos de un usuario" .
Dejo mi Solucion con muchos detalles ya que lo uso para repasar lo basico :

.
.
.
.
.
.
.
.
.
.
.
.
.
.

//Node.js
export class Node {
  constructor(name, age, bedNumber) {
    this.name = name
    this.age = age
    this.bedNumber = bedNumber
    this.next = null
  }
}
//exercise.js

import { Node } from "./Node";

export class PatientList {
  constructor(beds) {
    this.head = null
    this.tail = null
    this.beds = Array(beds).fill(true)
    this.length = 0
  }

  addPatient(name, age) {
//verifica si hay camas disponibles en el hospital

//this.beds para obtener una Arr de camas ocupadas y luego verificar su longitud
    if (this.beds.filter(bed => bed).length === 0) {
      throw new Error("No hay camas disponibles")
    }

//Si hay camas disponibles

//encuentra el índice de la primera cama disponible utilizando el método findIndex
    const availableBed = this.beds.findIndex(bed => bed)
//Luego, marca esa cama como ocupada
    this.beds[availableBed] = false
//nuevo objeto Node que representa al paciente con el nombre, la edad y el número de cama proporcionados
    const newPatient = new Node(name, age, availableBed + 1)
//Si la cola de pacientes está vacía, la cabeza y la cola auntan al mismo paciente
    if (!this.tail) {
      this.head = newPatient
      this.tail = newPatient
    } else {
//De lo contrario, se agrega el nuevo paciente al final de la cola y se actualiza el puntero de la cola
      this.tail.next = newPatient
      this.tail = newPatient
    }
    this.length++
  }



  removePatient(name) {
//si la lista de pacientes está vacía
    if (!this.head) {
      return null;
    }
//Si es el primer paciente en la lista
    if (this.head.name === name) {
//se elimina de la lista actualizando el puntero de la cabeza al siguiente paciente en la lista
      this.head = this.head.next;
//se libera la cama ocupada
      this.beds[0] = true
//actualisamos
      this.length--;
      return;
    }
//posicionamos el puntero, en el primer elemento de la lista 
    let currentPatient = this.head;
//Si el primer paciente no tiene el mismo nombre que el proporcionado, la función recorre la lista de pacientes
    while (currentPatient.next) {
//Si encuentra un paciente con el mismo nombre, lo elimina
      if (currentPatient.next.name === name) {
//desocupo la cama
        this.beds[currentPatient.bedNumber - 1] = true
//acomodo el siguiente puntero
        currentPatient.next = currentPatient.next.next;

        this.length--;
        return;
      }
//si no entra al IF, apunto al siguiente pasicnete, para compara nombres
      currentPatient = currentPatient.next;
    }
//si no se encuentra en toda la lista sale el error
    throw new Error("Paciente no encontrado")
  }

  getPatient(name) {
    let currentPatient = this.head;
//recorre la lista de pacientes,mientras que el siguiente no sea null
    while (currentPatient.next) {
//Si encuentra un paciente con el mismo nombre, devuelve un objeto
      if (currentPatient.name === name) {
        return {
          name: currentPatient.name,
          age: currentPatient.age,
          bedNumber: currentPatient.bedNumber
        }
      }
//apunto al siguiente, para seguir recorrientod toda la lista, con el While
      currentPatient = currentPatient.next;
    }
//si no encuentra el nombre, sale error
    throw new Error("Paciente no encontrado")
  }

  getPatientList() {
//en este Arr, voy a poner los pacientes
    let array = []
//apunto al primere paciente para recorre toda la lista
    let currentPatient = this.head
//recorre la lista de pacientes,mientras que no sea null
    while (currentPatient) {
//Para cada paciente en la lista, agrega un objeto en el Arr
      array.push({
        name: currentPatient.name,
        age: currentPatient.age,
        bedNumber: currentPatient.bedNumber
      })
//apunto al siguiente, para seguir recorrientod toda la lista, con el While
      currentPatient = currentPatient.next;
    }
    return array
  }

  getAvailableBeds() {
//método filter en el Arr "this.beds" para obtener un Arr de camas disponible
    return this.beds.filter(value => value).length
  }
}

Mi solución:
.
.
.
.
.
.
.
.
Node.js

export class Node {
  constructor(name, age, bedNumber) {
    this.name = name
    this.age = age
    this.bedNumber = bedNumber
    this.next = null
  }
}

exercise.js

import { Node } from "./Node";

export class PatientList {
  constructor(beds) {
    this.head = null
    this.tail = null
    this.beds = Array(beds).fill(true)
    this.length = 0
  }

  addPatient(name, age) {
    if (this.beds.filter(bed => bed).length === 0) {
      throw new Error("No hay camas disponibles")
    }
    const availableBed = this.beds.findIndex(bed => bed)
    this.beds[availableBed] = false
    const newPatient = new Node(name, age, availableBed + 1)
    if (!this.tail) {
      this.head = newPatient
      this.tail = newPatient
    } else {
      this.tail.next = newPatient
      this.tail = newPatient
    }
    this.length++
  }

  removePatient(name) {
    if (!this.head) {
      return null;
    }
    if (this.head.name === name) {
      this.head = this.head.next;
      this.beds[0] = true
      this.length--;
      return;
    }
    let currentPatient = this.head;
    while (currentPatient.next) {
      if (currentPatient.next.name === name) {
        this.beds[currentPatient.bedNumber - 1] = true
        currentPatient.next = currentPatient.next.next;
        this.length--;
        return;
      }
      currentPatient = currentPatient.next;
    }
    throw new Error("Paciente no encontrado")
  }

  getPatient(name) {
    let currentPatient = this.head;
    while (currentPatient.next) {
      if (currentPatient.name === name) {
        return {
          name: currentPatient.name,
          age: currentPatient.age,
          bedNumber: currentPatient.bedNumber
        }
      }
      currentPatient = currentPatient.next;
    }
    throw new Error("Paciente no encontrado")
  }

  getPatientList() {
    let array = []
    let currentPatient = this.head
    while (currentPatient) {
      array.push({
        name: currentPatient.name,
        age: currentPatient.age,
        bedNumber: currentPatient.bedNumber
      })
      currentPatient = currentPatient.next;
    }
    return array
  }

  getAvailableBeds() {
    return this.beds.filter(value => value).length
  }
}

export class PatientList {
  constructor(beds) {
    this.head = null; 
    this.tail = null; 
    this.beds = beds; 
    this.availableBeds = beds;
  }

  addPatient(name, age) {
    if (this.availableBeds <= 0) {
      throw new Error("No hay camas disponibles");
    }
    const patient = {
      name,
      age,
      bedNumber: this.beds - this.availableBeds + 1,
    };
    const node = new Node(patient);
    if (!this.head) {
      this.head = node;
      this.tail = node;
    } else {
      this.tail.next = node;
      this.tail = node;
    }
    this.availableBeds--;
  }

  removePatient(name) {
    let current = this.head;
    let prev = null;
    while (current) {
      if (current.data.name === name) {
        if (!prev) {
          // si es el primer nodo
          this.head = current.next;
          if (!this.head) {
            // si era el último nodo
            this.tail = null;
          }
        } else {
          prev.next = current.next;
          if (!current.next) {
            // si era el último nodo
            this.tail = prev;
          }
        }
        this.availableBeds++;
        return;
      }
      prev = current;
      current = current.next;
    }
    throw new Error("Paciente no encontrado");
  }

  getPatient(name) {
    let current = this.head;
    while (current) {
      if (current.data.name === name) {
        return current.data;
      }
      current = current.next;
    }
    throw new Error("Paciente no encontrado");
  }

  getPatientList() {
    const list = [];
    let current = this.head;
    while (current) {
      list.push(current.data);
      current = current.next;
    }
    return list;
  }

  getAvailableBeds() {
    return this.availableBeds;
  }
}

Hola, dejo mi solución,
.
.
.
.
.
.
.
.
.
.
.

Solo tengo un detallito, me regresa el error Should throw error if patient not found aunque si estoy regresando el mensaje de error, alguno de ustedes visualiza ¿que es lo que tengo mal al momento de enviar el error de paciente no encontrado?
Muchas gracias de antemano por su ayuda 🌸✨💻

export class Node {
  constructor(name, age, bedNumber) {
    // Tu código aquí 👈🏻
    this.name = name;
    this.age = age;
    this.bedNumber = bedNumber;
    this.next = null;
  }
}

export class PatientList {
  constructor(beds) {
    // Tu código aquí 👈🏻this.beds = beds;
    this.head = null;
    this.tail = null;
    this.length = 0;
    this.availableBeds = beds;
    this.availableBedsArray = [];
    for (let i = 1; i <= beds; i++) {
      this.availableBedsArray.push(i);
    }
  }

  addPatient(name, age) {
    // Tu código aquí 👈🏻
    if (this.availableBedsArray.length === 0) {
      throw new Error(`No hay camas disponibles`)
    };

    const newNode = new Node(name, age, this.availableBedsArray[0]);
    this.availableBedsArray.shift();

    if (!this.head) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      this.tail = newNode;
    }
    this.length++;
    this.availableBeds--;
  }

  removePatient(name) {
    // Tu código aquí 👈🏻
    if (this.head === null) {
      throw new Error("Paciente no encontrado");
    }
    if (this.head.name === name) {
      this.availableBedsArray.push(this.head.bedNumber);
      this.head = this.head.next;
      this.length--;
      this.availableBeds--;
      return;
    }
    let currentNode = this.head;
    while (currentNode.next) {
      if (currentNode.next.name === name) {
        this.availableBedsArray.push(this.head.bedNumber);
        currentNode.next = currentNode.next.next;
        this.length--;
        this.availableBeds--;
        return;
      }
      currentNode = currentNode.next;
    }
    if (this.head === null) {
      throw new Error("Paciente no encontrado");
    }
  }

  getPatient(name) {
    if (this.head === null) {
      throw new Error("Paciente no encontrado");
    }
    // Tu código aquí 👈🏻
    let currentNode = this.head;
    let findPatient = false;
    for (let i = 0; i < this.length; i++) {
      if (i === 0 && currentNode?.name === name) {
        findPatient = true;
        return {
          name: currentNode.name,
          age: currentNode.age,
          bedNumber: currentNode.bedNumber,
        };
      } else {
        currentNode = currentNode.next;
        if (currentNode?.name === name) {
          findPatient = true;
          return {
            name: currentNode.name,
            age: currentNode.age,
            bedNumber: currentNode.bedNumber,
          };
        }
      }
    }
    if (!findPatient) {
      throw new Error("Paciente no encontrado")
    }
    return null;
  }

  getPatientList() {
    // Tu código aquí 👈🏻
    let currentNode = this.head;
    let currentNodeArray = [];
    for (let i = 0; i < this.length; i++) {
      if (i === 0) {
        currentNodeArray.push({
          name: currentNode.name,
          age: currentNode.age,
          bedNumber: currentNode.bedNumber,
        });
      } else {
        currentNode = currentNode.next;
        currentNodeArray.push({
          name: currentNode.name,
          age: currentNode.age,
          bedNumber: currentNode.bedNumber,
        })
      }
    }
    return currentNodeArray;
  }

  getAvailableBeds() {
    // Tu código aquí 👈🏻
    return this.availableBedsArray.length;
  }
}

Que lio me estaba armando con el control del array de numeros de habitacion por poner la restauracion de la habitacion que queda libre en orden incorrecto xDDDD

Creo que ahora si.

,
,
,
,
,
,
,
,
,
,
,
,
,
,

import { Node } from "./Node";

export class PatientList {
  constructor(totalBeds) {
    this.head = null;
    this.totalBeds = totalBeds;
    this.bedsAvailable = [];
    for (let i = 1; i <= this.totalBeds; i++) {
      this.bedsAvailable.push(i);
    }
    this.nextBedNumber = 1;
  }

  addPatient(name, age) {
    if (this.totalBeds === 0) {
      throw new Error("No hay camas disponibles");
    }

    this.bedsAvailable.sort();
    const newPatient = {
      name,
      age,
      bedNumber: this.bedsAvailable[0],
      next: null,
    };
    this.bedsAvailable.shift();

    if (this.head === null) {
      this.head = newPatient;
    } else {
      let current = this.head;
      while (current.next !== null) {
        current = current.next;
      }
      current.next = newPatient;
    }

    this.nextBedNumber++;
    this.totalBeds--;
  }

  removePatient(name) {
    if (this.head === null) {
      throw new Error("Paciente no encontrado");
    }

    if (this.head.name === name) {
      this.totalBeds++;
      this.bedsAvailable.push(this.head.bedNumber);
      this.head = this.head.next;
      return;
    }

    let previous = this.head;
    let current = this.head.next;

    while (current !== null) {
      if (current.name === name) {
        this.totalBeds++;
        previous.next = current.next;
        return;
      }
      previous = current;
      current = current.next;
    }

    throw new Error("Paciente no encontrado");
  }

  getPatient(name) {
    let current = this.head;

    while (current !== null) {
      if (current.name === name) {
        return {
          name: current.name,
          age: current.age,
          bedNumber: current.bedNumber,
        };
      }
      current = current.next;
    }

    throw new Error("Paciente no encontrado");
  }

  getPatientList() {
    const patientList = [];
    let current = this.head;

    while (current !== null) {
      patientList.push({
        name: current.name,
        age: current.age,
        bedNumber: current.bedNumber,
      });
      current = current.next;
    }

    return patientList;
  }

  getAvailableBeds() {
    return this.totalBeds;
  }
}

Adjunto una noble solucion!
.
.
.
.
.
.
.
.
.

export class Node {
  constructor(name, age, bedNumber) {
    this.name = name;
    this.age = age;
    this.bedNumber = bedNumber;
    this.next = null;
  }
}

import { Node } from './Node.js';

export class PatientList {
  constructor(beds) {
    this.beds = [...Array(beds).keys()].map((i) => i + 1);
    this.head = null;
    this.tail = null;
    this.length = 0;
  }

  addPatient(name, age) {
    if (this.beds.length === 0) throw new Error('No hay camas disponibles');

    const newNode = new Node(name, age, this.beds[0]);
    this.beds.shift();
    if (!this.head) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      this.tail = newNode;
    }
    this.length++;
  }

  removePatient(name) {
    if (!this.head) {
      return null;
    }
    if (this.head.name === name) {
      this.beds.push(this.head.bedNumber);
      this.head = this.head.next;
      this.length--;
      return;
    }
    let currentNode = this.head;
    while (currentNode.next) {
      if (currentNode.next.name === name) {
        this.beds.push(currentNode.next.bedNumber);
        currentNode.next = currentNode.next.next;
        this.length--;
        return;
      }
      currentNode = currentNode.next;
    }
    throw new Error('Paciente no encontrado');
  }

  getPatient(name) {
    let pointerSearch = this.head;
    let i = 0;
    while (pointerSearch.name !== name && pointerSearch.next != null) {
      pointerSearch = pointerSearch.next;
      i++;
    }

    if (!pointerSearch.next) throw new Error('Paciente no encotrado');

    const { next, ...patientInfo } = pointerSearch;

    return patientInfo;
  }

  getPatientList() {
    if (this.length === 0) return [];
    const patientListArray = [
      {
        name: this.head.name,
        age: this.head.age,
        bedNumber: this.head.bedNumber,
      },
    ];

    let currentNode = this.head;
    while (currentNode.next) {
      patientListArray.push({
        name: currentNode.next.name,
        age: currentNode.next.age,
        bedNumber: currentNode.next.bedNumber,
      });
      currentNode = currentNode.next;
    }
    return patientListArray;
  }

  getAvailableBeds() {
    return this.beds.length;
  }
}

Mi solución:
.
.
.
.
.
.
.
.
.
.
.
.
código “Class Node.js”:

export class Node {
  constructor(name, age, bedNumber) {
    this.name = name;
    this.age = age;
    this.bedNumber = bedNumber;
    this.next = null;
  }
}

código “exercise.js”:

import { Node } from "./Node";

export class PatientList {
  constructor(beds) {
    this.beds = beds;
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  addPatient(name, age) {
    if (this.length == 0) {
      const newNode = new Node(name, age, 1);
      this.head = newNode;
      this.tail = newNode;
      this.length++;
      return this;
    }
    if (this.length == this.beds)
      throw new Error("No hay camas disponibles");

    const numBed = this.bedAvailable();
    const newNode = new Node(name, age, numBed);
    this.tail.next = newNode;
    this.tail = newNode;
    this.length++;
    return this;
  }

  removePatient(name) {
    let currentNode = this.head;
    let nodePrev;
    if(this.length>0){
      while (currentNode.name != name) {
        nodePrev = currentNode;
        currentNode = currentNode.next;
      }
    }
    if (currentNode) {
      if (currentNode === this.head) {
        this.head = this.head.next;
      } else if (currentNode === this.tail) {
        this.tail = nodePrev;
        nodePrev.next = null;
      } else {
        nodePrev.next = currentNode.next;
      }
      this.length--;
      return this;
    } else {
      throw new Error("Paciente no encontrado");
    }
  }

  getPatient(name) {
    let currentNode = this.head;
    for (let i = 0; i < this.length - 1; i++) {
      if (currentNode.name == name)
        return {
          "name": currentNode.name,
          "age": currentNode.age,
          "bedNumber": currentNode.bedNumber
        };
      currentNode = currentNode.next;
    }
    throw new Error("Paciente no encontrado");
  }

  getPatientList() {
    let currentNode = this.head;
    let arrayPatients = [];
    for (let i = 0; i < this.length; i++) {
      arrayPatients.push({
        "name": currentNode.name,
        "age": currentNode.age,
        "bedNumber": currentNode.bedNumber
      });
      currentNode = currentNode.next;
    }
    return arrayPatients;
  }

  getAvailableBeds() {
    return (this.beds - this.length);
  }
  bedAvailable() {
    let curretNode = this.head;
    let beds = [];
    for (let j = 0; j < this.length; j++) {
      beds.push(curretNode.bedNumber);
      curretNode = curretNode.next;
    }
    for (let i = 1; i <= this.beds; i++) {
      if (!beds.includes(i))
        return i;
    }
  }
}

Aquí les dejo mi solución:
.
.
.
.
.
.
.
.
.
.
.
.
.
.

import { Node } from "./Node";

export class PatientList {
  constructor(beds) {
    this.totalbeds = beds;
    this.head = null;
    this.tail = null;
    this.totalPatients = 0;
    this.availableBeds = [];
    for (let i = 0; i < this.totalbeds; i++) {
      this.availableBeds.push(i + 1);
    }
  }

  addPatient(name, age) {
    
    if (this.availableBeds.length === 0)
      throw new Error("No hay camas disponibles");

    const patient = new Node(name, age, this.availableBeds[0]);

    if (!this.head) {
      this.head = patient;
      this.tail = patient;
    }
    else {
      this.tail.next = patient;
      this.tail = patient;
    }
    this.totalPatients++
    this.availableBeds.shift();

  }

  removePatient(name) {
    if (name.length === 0) return null;

    if (name === this.head.name) {
      this.availableBeds.push(this.head.bedNumber);
      this.head = this.head.next;
      this.totalPatients--;
      return;
    }
    let currentPatient = this.head;
    while (currentPatient.next) {
      if (currentPatient.next.name === name) {
        this.availableBeds.push(currentPatient.bedNumber);
        currentPatient.next = currentPatient.next.next;
        this.totalPatients--;
        return;
      }
      currentPatient = currentPatient.next;
    }
    throw new Error("Paciente no encontrado");
  }

  getPatient(name) {
    if (name.length === 0) return null;

    if (name === this.head.name) {
      const { name, age, bedNumber } = this.head;
      return { name, age, bedNumber };
    }
    if (name === this.tail.name) {
      const { name, age, bedNumber } = this.tail;
      return { name, age, bedNumber };
    }

    let currentPatient = this.head;
    while (currentPatient.next) {
      if (currentPatient.next.name === name) {
        return currentPatient.next;
      }
      currentPatient = currentPatient.next;
    }

    throw new Error("Paciente no encontrado");
  }

  getPatientList() {
    if (!this.head) return [];
    const { name, age, bedNumber } = this.head;
    const patientList = [{ name, age, bedNumber }];

    let currentPatient = this.head;
    while (currentPatient.next) {      
      currentPatient = currentPatient.next;
      const { name, age, bedNumber } = currentPatient;
      patientList.push({ name, age, bedNumber });
    }
    return patientList;
  }

  getAvailableBeds() {
    return this.availableBeds.length;
  }
}

🛡️🛡️🛡️Escudo anti spoilers🛡️🛡️🛡️

Implementación de un singly linked list

Con los conceptos claros de una singly linked list resulta muy sencillo 😎

Nunca pares de aprender 🦾

Node.js

export class Node {
  constructor(name, age, bedNumber) {
    this.name = name;
    this.age = age;
    this.bedNumber = bedNumber;
    this.next = null;
  }
}

exercise.js

export class PatientList {
  constructor(beds) {
    this.beds = Array.from({ length: beds }, (_, i) => i + 1);
    this.lenght = 0;
    this.head = null;
    this.tail = null;
  }

  addPatient(name, age) {
    if (this.beds.length != 0) {
      const newPatient = new Node(name, age, this.beds[0]);
      this.beds.shift();
      if (!this.head) {
        this.head = newPatient;
        this.tail = newPatient;
      } else {
        this.tail.next = newPatient;
        this.tail = newPatient;
      }
      this.lenght++;
      return;
    }
    throw new Error("No hay camas disponibles");
  }

  removePatient(name) {
    if (this.head.name == name) {
      this.beds.push(this.head.bedNumber);
      this.head = this.head.next;
      this.lenght--;
      return;
    }
    let currentPatient = this.head;
    while (currentPatient.next) {
      if (currentPatient.next.name == name) {
        this.beds.push(currentPatient.next.bedNumber);
        currentPatient.next = currentPatient.next.next;
        this.lenght--;
        return;
      }
      currentPatient = currentPatient.next;
    }
    throw new Error("Paciente no encontrado");
  }

  getPatient(name) {
    if (this.head.name == name) {
      return {
        name: this.head.name,
        age: this.head.age,
        bedNumber: this.head.bedNumber,
      };
    }
    let currentPatient = this.head;
    while (currentPatient.next) {
      if (currentPatient.next.name == name) {
        return {
          name: currentPatient.next.name,
          age: currentPatient.next.age,
          bedNumber: currentPatient.next.bedNumber,
        };
      }
    }
    throw new Error("Paciente no encotrado");
  }

  getPatientList() {
    const patientListArr = [];
    if (this.head) {
      patientListArr.push({
        name: this.head.name,
        age: this.head.age,
        bedNumber: this.head.bedNumber,
      });
    }
    let currentPatient = this.head;
    while (currentPatient.next) {
      patientListArr.push({
        name: currentPatient.next.name,
        age: currentPatient.next.age,
        bedNumber: currentPatient.next.bedNumber,
      });
      currentPatient = currentPatient.next;
    }
    return patientListArr;
  }

  getAvailableBeds() {
    return this.beds.length;
  }
}
undefined