用某个值快速填充数组_用顺序值填充数组

用某个值快速填充数组

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调试器...),我将分享更多我的贡献!

翻译自: https://davidwalsh.name/fill-array-javascript

用某个值快速填充数组

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值