software-tools-books / js4ds

JavaScript for Data Science
https://third-bit.com/js4ds/
Other
185 stars 31 forks source link

Possible typo in Chapter: Manipulating Pages, Section: Sortable Lists, in initial script of sortLists function #220

Closed shafayetShafee closed 1 year ago

shafayetShafee commented 3 years ago

Hi, While I was reading through the chapter Manipulating pages, in the Sortable Lists section I got stuck with this initial script of sortLists function

const sortLists = () => {
  const allLists = Array.from(document.querySelectorAll('#sorted'))
  lists.forEach((list) => {
    const children = Array.from(list.childNodes)
          .filter(c => c.nodeName !== '#text')
    children.sort((left, right) =>
                  left.textContent.localeCompare(right.textContent))
    while (list.firstChild) {
      list.removeChild(list.firstChild)
    }
    children.forEach(c => list.appendChild(c))
  })
}

In the second line, a variable allLists is defined as an array but in the third line a variable lists is used ( it should be allLists), and also, in the HTML file there was class="sorted", but here in this script in querySelectorAll('#sorted') is used. :confused:

But after a while, scrolling down a bit, I found this function again, where everything is correct. :smiley: I don't know if those mistakes were intentional (for learning purpose), so I thought I just let the authors know. :sweat_smile: :sweat_smile: :blush:

itmeson commented 1 year ago

I think this was a typo -- I currently see the allLists --> lists issue fixed, but the first copy of that script still has '#sorted' in the querySelectorAll, while the second copy has the correct '.sorted'