Fill an Array with Sequential Values

I’ve been contributing to Mozilla’s awesome DevTools debugger because, well, I want to give back to the Firefox Engineers and all the developers who have stayed loyal to Firefox.  Having my hand in loads of Mozilla projects is really satisfying, especially for my ego.

In any event, one task required me to fill an array with every number in a sequence, then I would filter out unwanted items based on another array.  Here’s how you can fill a range within an array:

const fillRange = (start, end) => { return Array(end - start + 1).fill().map((item, index) => start + index);
}; const allLines = fillRange(0, numLines - 1); // [1, 2, 3, 4, 5, ...]

From there I could filter out what I didn’t want:</<p>p>

let executableLines = [/* series of line numbers with code */];
const emptyLines = allLines.filter(i => !executableLines.includes(i));

When the feature gets merged (…and no one complains about their Firefox debugger…) I’ll share more about  my contribution!

Related Post

Rojenx is a leading concept artist who work appears in games and publications

Check out his personal gallery here

In other news …