本帖最后由 flashercs 于 2019-3-3 18:08 编辑
- /**
- * delete a member in an array for every nScale numbers loop;
- * @param aInput The input array with sequence members
- * @param nScale The granularity of the members removation
- * @param nRemained The remained members count in the array
- */
- function removeNO3(aInput = [1, 2, 3, 4, 5, 6], nScale = 3, nRemained = 1) {
- var i = 0;
- aOutput = aInput.slice(0);
- --nScale;
- while (aOutput.length > nRemained) {
- i = (i + nScale) % aOutput.length;
- aOutput.splice(i, 1);
- }
- return aOutput;
- }
复制代码
- removeNO3([1,2,3,4,5,6,7,8,9,10]);
- removeNO3([1,2,3,4,5,6,7,8,9,10],undefined,2);
- removeNO3([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],undefined,3);
复制代码
|