Sha256: 438fee823940480024fdbdd161b2fcbf1a754e37be978682bfac2c7ffab7f47b

Contents?: true

Size: 1.09 KB

Versions: 39

Compression:

Stored size: 1.09 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

39 entries across 24 versions & 1 rubygems

Version Path
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.5.4 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.5.3 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.5.2 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.5.1 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.5.0 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.4.11 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.4.9 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.4.9 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.4.8 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.4.8 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.4.7 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.4.7 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.4.6 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.4.6 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/ArrayGetItemHandler.js
javonet-ruby-sdk-2.4.5 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/ArrayGetItemHandler.js