Consider this very simple code:
someLabel:
for (var i=0; i<newFonts.length; i++) {
var newFont = newFonts[i];
for (var j=0; j<oldFonts.length; j++) {
var oldFont = oldFonts[j];
if (fb.equals(oldFont, newFont)) {
// Break out of inner loop, don't finish outer iteration, continue with next outer item
continue 2;
}
}
// This must only happen if `newFont` doesn't match ANY `oldFonts`
oldFonts.push(newFont);
}
What it's supposed to do is compare all oldFonts
objects with newFonts
objects and only add newFont
to oldFonts
(oldFonts.push
) if it doesn't already exist (fb.equals
).
oldFonts
and newFonts
are objects with name
and host
properties. Both are used in fb.equals()
to determine equality. indexOf()
won't work.
This is exactly how I'd do it in PHP. It doesn't work in JS, because JS doesn't support continue 2
, which means continue 2 levels.
How do I do this in JS??
continue
wont do, because it'll still finish the inner loop and end up at thepush
break
won't do, because it'll skip the inner loop and jump straight to thepush
break someLabel
won't do, because I don't want to skip ALLnewFonts
when ONE must be ignored
This must be possible without a single function...