用某个值快速填充数组
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.
我一直在为Mozilla出色的DevTools调试器做出贡献,因为我想回馈Firefox工程师和所有忠于Firefox的开发人员。 参与Mozilla项目的工作真的很令人满意,特别是对于我的自我。
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);
// [0, 1, 2, 3, 4, 5, ...]
From there I could filter out what I didn't want:
从那里我可以过滤掉我不想要的东西:
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!
当功能合并后(...没有人抱怨他们的Firefox调试器...),我将分享更多我的贡献!
用某个值快速填充数组