MCPcopy Create free account
hub / github.com/cryptii/cryptii / removeBricks

Method removeBricks

src/Pipe.js:289–308  ·  view source on GitHub ↗

* Removes bricks from the pipe. * Convenience method calling Pipe.spliceBricks internally. * @param {Brick[]|number[]} bricksOrIndexes Array of bricks or indexes * to be removed * @throws {Error} If one of the bricks is not part of the pipe. * @return {Pipe} Fluent interface

(bricksOrIndexes)

Source from the content-addressed store, hash-verified

287 * @return {Pipe} Fluent interface
288 */
289 removeBricks (bricksOrIndexes) {
290 bricksOrIndexes
291 // Map brick instances to indexes
292 .map(brickOrIndex => {
293 let index = brickOrIndex
294 if (brickOrIndex instanceof Brick) {
295 index = this._bricks.indexOf(brickOrIndex)
296 if (index === -1) {
297 throw new Error(
298 'Brick is not part of the pipe and thus can\'t be removed.')
299 }
300 }
301 return index
302 })
303 // Sort indexes in descending order
304 .sort((a, b) => b - a)
305 // Remove each
306 .forEach(index => this.spliceBricks(index, 1))
307 return this
308 }
309
310 /**
311 * Replaces a single brick.

Callers

nothing calls this directly

Calls 2

spliceBricksMethod · 0.95
indexOfMethod · 0.80

Tested by

no test coverage detected