Reading Eloquent JavaScript...can I ever get this good?

Reading Eloquent JavaScript...can I ever get this good?
0.0 0

#1

after reading chapter 5 of Eloquent JavaScript I’m actually shocked at the level of sophistication in the code written there. The way the author puts together the logic/sequences of thought in his code is nothing short of art.

I guess what I want to ask is - is it common for developers to be able to write code to that level of eloquence with some experience (and if so, typically after how long?) or is the code displayed in the book something only writeable by coding prodigies/ super talented CS grads?


#2

I haven’t read the book so cannot judge. Can you give some examples of the sophistication?


#3

a program to take a string and identify what percentage of whatever Unicode scripts are present in it out of the total. the program also accounts for Unicode characters which take up more than one code unit

each unicode script is modelled as such and placed in an array called SCRIPTS:

{
  name: "Coptic",
  ranges: [[994, 1008], [11392, 11508], [11513, 11520]],
  direction: "ltr",
  year: -200,
  living: false,
  link: "https://en.wikipedia.org/wiki/Coptic_alphabet"
}
function characterScript(code) {
  for (let script of SCRIPTS) {
    if (script.ranges.some(([from, to]) => {
      return code >= from && code < to;
    })) {
      return script;
    }
  }
  return null;
}

function countBy(items, groupName) {
  let counts = [];
  for (let item of items) {
    let name = groupName(item);
    let known = counts.findIndex(c => c.name == name);
    if (known == -1) {
      counts.push({name, count: 1});
    } else {
      counts[known].count++;
    }
  }
  return counts;
}

function textScripts(text) {
  let scripts = countBy(text, char => {
    let script = characterScript(char.codePointAt(0));
    return script ? script.name : "none";
  }).filter(({name}) => name != "none");

  let total = scripts.reduce((n, {count}) => n + count, 0);
  if (total == 0) return "No scripts found";

  return scripts.map(({name, count}) => {
    return `${Math.round(count * 100 / total)}% ${name}`;
  }).join(", ");
}

console.log(textScripts('英国的狗说"woof", 俄罗斯的狗说"тяв"'));
// → 61% Han, 22% Latin, 17% Cyrillic

#4

Well I presume it is explained in the book but looking at it, it is hard to read as there are no comments anywhere.

I can see he has used as many different methods as possible I guess to illustrate what each can do.

Like with any problem it is a case of breaking it down to simple tasks.
If you want to improve your coding I would recommend a site like codewars.com.


#5

Hi,

Actually many people complain about how hard the book gets after chapters 5 or 6. I read many chapters myself and yes, you freak out when you can’t follow those examples. But this is just like any language: when you begin to learn it, everything looks difficult as hell and you think you won’t be able to speak that language unless you know every word or expression. The reality is very different, though: once you get up and running with it, you will be able to move forward finding whatever you need to express more clearly one day after another. In Javascript terms, you have many resources to practice your logic and knowledge so you can improve your habilities with the language.

As of the time taken to get to this level… I guess it’s like everything else in this world. You just practice and you’ll find out yourself :slight_smile:

Happy coding!


#6

thank you very much, ill keep pushing on