MCPcopy
hub / github.com/jstat/jstat / _slice

Function _slice

src/core.js:442–475  ·  view source on GitHub ↗
(list, start, end, step)

Source from the content-addressed store, hash-verified

440// as numpy code A[:2,1:]
441jStat.slice = (function(){
442 function _slice(list, start, end, step) {
443 // note it's not equal to range.map mode it's a bug
444 var i;
445 var rl = [];
446 var length = list.length;
447 if (start === undefined && end === undefined && step === undefined) {
448 return jStat.copy(list);
449 }
450
451 start = start || 0;
452 end = end || list.length;
453 start = start >= 0 ? start : length + start;
454 end = end >= 0 ? end : length + end;
455 step = step || 1;
456 if (start === end || step === 0) {
457 return [];
458 }
459 if (start < end && step < 0) {
460 return [];
461 }
462 if (start > end && step > 0) {
463 return [];
464 }
465 if (step > 0) {
466 for (i = start; i < end; i += step) {
467 rl.push(list[i]);
468 }
469 } else {
470 for (i = start; i > end;i += step) {
471 rl.push(list[i]);
472 }
473 }
474 return rl;
475 }
476
477 function slice(list, rcSlice) {
478 var colSlice, rowSlice;

Callers 1

sliceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected