Answer

Answer

t.me/js_test

Ответ:

const printList = list => {
 let currEl = list;

 while (currEl) {
  console.log(currEl.value);
  currEl = currEl.next;
 }
}

Обьяснение:

Мы используем переменную currEl для перемещения по списку. Как только currEl.next вернёт нам null - мы понимаем, что прошли весь список и выходим из цикла.

Код для проверки:

let list = {
 value: 1,
 next: {
  value: 2,
  next: {
   value: 3,
   next: {
    value: 4,
    next: null
   }
  }
 }
};

const printList = list => {
 let currEl = list;

 while (currEl) {
  console.log(currEl.value);
  currEl = currEl.next;
 }
}

printList(list);


Report Page