JSFiddle - React, Tailwind, and code Playground

by Salmin Skenderovic

JavaScript

let i = 0
let root = {
  index: i
}
let node = root

while (i < 10) {
  const copy = {
    ...node
  }
  node.next = node = {} // `node` in `node.next` is the old `node`
  node.index = ++i // `node` in `node.index` is the new `node`
}

console.log(root.next.next.next.next)

node = root
do {
  //console.log(node.index) // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
} while ((node = node.next))