* Moves brick to given index. * @param {Brick} brick Pipe brick to be moved * @param {number} index Index the brick should be moved to * @return {Pipe} Fluent interface
(brick, index)
| 246 | * @return {Pipe} Fluent interface |
| 247 | */ |
| 248 | moveBrick (brick, index) { |
| 249 | const fromIndex = this._bricks.indexOf(brick) |
| 250 | if (fromIndex === -1) { |
| 251 | throw new Error('Brick is not part of the pipe.') |
| 252 | } |
| 253 | if (index > fromIndex) { |
| 254 | index-- |
| 255 | } |
| 256 | this.spliceBricks(fromIndex, 1) |
| 257 | this.spliceBricks(index, 0, [brick]) |
| 258 | return this |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Removes single brick from the pipe. |
no test coverage detected