I am working through multiple different resources to learn JS. This particular one, Eloquent Javascript, is pretty tough, and I find a lot of explanations are minimal or are left for you to figure it out. Which is fine; I just move through it slower and ask a lot of questions on SO :P
Anyway, here is the full function:
function characterScript(code) {
for (let script of SCRIPTS) {
if (script.ranges.some(([from, to]) => {
return code >= from && code < to;
})) {
return script;
}
}
return null;
}
console.log(characterScript(121));
// → {name: "Latin", …}
I've worked through it but was reviewing tonight and realized I didn't completely understand the IF statement. My basic understanding of IF conditions is that:
if (true) {
do this
} else {
do that
But I don't understand how the if statement:
if (script.ranges.some(([from, to]) => {
return code >= from && code < to;
}))
is evaluating to true here. Here is a sample object reference:
var SCRIPTS = [
{
name: "Adlam",
ranges: [[125184, 125259], [125264, 125274], [125278, 125280]],
direction: "rtl",
year: 1987,
living: true,
link: "https://en.wikipedia.org/wiki/Fula_alphabets#Adlam_alphabet"
},
Thanks to everyone who has replied to my past questions and this great community in advance. By the way, I'm not confused about the destructuring of the ranges array (from, to).
Thanks again!
Jordan
Aucun commentaire:
Enregistrer un commentaire