marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.03k stars 799 forks source link

CH. 5 strings and character codes - suggestion on reformatting example code #338

Closed Nick-Gottschlich closed 6 years ago

Nick-Gottschlich commented 6 years ago

Hey there,

I'm going through the third edition right now. At this point there is a code block formatted like this:

function characterScript(code) {
  for (let script of SCRIPTS) {
    if (script.ranges.some(([from, to]) => code >= from &&
                                           code < to)) {
      return script;
    }
  }
  return null;
}

IMO it is much easier to read like this:

function characterScript(code) {
  for (let script of SCRIPTS) {
    if (script.ranges.some(([from, to]) => {
      return (code >= from && code < to);
    })) {
      return script;
    }
  }
  return null;
}

The switch from the fat arrow (=>) to greater than or equals (>=) will definitely confuse people, separating them with brackets makes it much more readable.

Awesome book, I'm learning a ton going through it!

dhollinden commented 6 years ago

"The switch from the fat arrow (=>) to greater than or equals (>=) will definitely confuse people"

I stumbled on that for a bit.

marijnh commented 6 years ago

Attached patch makes this change.

dhollinden commented 6 years ago

Thumbs up. Thanks.