MCPcopy Create free account
hub / github.com/immutable-js/immutable-js / splice

Function splice

src/CollectionImpl.js:580–597  ·  view source on GitHub ↗
(index, removeNum /*, ...values*/)

Source from the content-addressed store, hash-verified

578 },
579
580 splice(index, removeNum /*, ...values*/) {
581 const numArgs = arguments.length;
582 removeNum = Math.max(removeNum || 0, 0);
583 if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
584 return this;
585 }
586 // If index is negative, it should resolve relative to the size of the
587 // collection. However size may be expensive to compute if not cached, so
588 // only call count() if the number is in fact negative.
589 index = resolveBegin(index, index < 0 ? this.count() : this.size);
590 const spliced = this.slice(0, index);
591 return reify(
592 this,
593 numArgs === 1
594 ? spliced
595 : spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
596 );
597 },
598
599 // ### More collection methods
600

Callers

nothing calls this directly

Calls 7

resolveBeginFunction · 0.90
reifyFunction · 0.90
arrCopyFunction · 0.85
maxMethod · 0.80
countMethod · 0.80
sliceMethod · 0.65
concatMethod · 0.65

Tested by

no test coverage detected