Sha256: fe215d0a7a581423d769598406c3f5031b42ef6d1e962e5d35e0a350b07f663c
Contents?: true
Size: 1.12 KB
Versions: 15
Compression:
Stored size: 1.12 KB
Contents
const AbstractHandler = require("./AbstractHandler") class ArrayGetItemHandler extends AbstractHandler { requiredParametersCount = 2 constructor() { super() } process(command) { try { if (command.payload.length < this.requiredParametersCount) { throw new Error("Array Get Item parameters mismatch") } let array = command.payload[0] let indexes if (Array.isArray(command.payload[1])) { indexes = command.payload[1] } else { indexes = command.payload.slice(1) } if (indexes.length === 1) { return array[indexes] } else { let array_copy = [...array] for (let i = 0; i < indexes.length; i++) { array_copy = array_copy[indexes[i]] } return array_copy } } catch (error) { throw this.process_stack_trace(error, this.constructor.name) } } } module.exports = new ArrayGetItemHandler()
Version data entries
15 entries across 15 versions & 1 rubygems