Selecting every nth item from an array

后端 未结 8 1866
春和景丽
春和景丽 2021-02-02 13:41

What would be the most efficient way to select every nth item from a large array? Is there a \'smart\' way to do it or is looping the only way?

Some points to c

8条回答
  •  你的背包
    2021-02-02 14:15

    If this really is a bottleneck, you might want to consider rethinking your design in order to make it numerically indexed.

    EDIT: Or create and maintain a seperate array with just the 205th items (which gets updated at insert or something like that).

提交回复
热议问题