How to use the array-move.mut function in array-move

To help you get started, we’ve selected a few array-move examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thiagodp / concordialang / modules / testscenario / StepUtil.ts View on Github external
if ( NodeTypes.STEP_GIVEN === step.nodeType
                || ( NodeTypes.STEP_AND == step.nodeType && true === lastWasGiven ) ) {

                const hasPrecondition = isDefined( step.nlpResult )
                    && nlpUtil.hasEntityNamed( Entities.STATE, step.nlpResult );

                if ( hasPrecondition ) {

                    // Does not have prior GIVEN ? -> Make it a GIVEN
                    if ( preconditionCount < 1 ) {
                        newSteps[ index ].nodeType = NodeTypes.STEP_GIVEN;
                    }

                    if ( preconditionCount != index ) {
                        arrayMove.mut( newSteps, index, preconditionCount );
                    }

                    // Is the next step an AND step ?
                    if ( index + 1 < stepCount && newSteps[ index + 1 ].nodeType === NodeTypes.STEP_AND ) {
                        let nextStep = newSteps[ index + 1 ];
                        // Make it a GIVEN step
                        nextStep.nodeType = NodeTypes.STEP_GIVEN;
                        // Change the sentence content!
                        if ( !! nextStep.content ) {
                            const stepAndKeyword: string = ( keywords.stepAnd || [ 'and' ] )[ 0 ];
                            const stepGivenKeyword: string = ( keywords.stepGiven || [ 'given' ] )[ 0 ];
                            const regex = new RegExp( stepAndKeyword, 'i' );
                            nextStep.content = nextStep.content.replace( regex, convertCase( stepGivenKeyword, CaseType.PASCAL ) ); // Given ...
                        }
                    }
github thiagodp / concordialang / dist / modules / testscenario / StepUtil.js View on Github external
let lastWasGiven = null;
        let index = 0, preconditionCount = 0;
        const stepCount = steps.length;
        let newSteps = deepcopy(steps); // << important
        for (let step of steps) {
            if (NodeTypes_1.NodeTypes.STEP_GIVEN === step.nodeType
                || (NodeTypes_1.NodeTypes.STEP_AND == step.nodeType && true === lastWasGiven)) {
                const hasPrecondition = TypeChecking_1.isDefined(step.nlpResult)
                    && nlpUtil.hasEntityNamed(nlp_1.Entities.STATE, step.nlpResult);
                if (hasPrecondition) {
                    // Does not have prior GIVEN ? -> Make it a GIVEN
                    if (preconditionCount < 1) {
                        newSteps[index].nodeType = NodeTypes_1.NodeTypes.STEP_GIVEN;
                    }
                    if (preconditionCount != index) {
                        arrayMove.mut(newSteps, index, preconditionCount);
                    }
                    // Is the next step an AND step ?
                    if (index + 1 < stepCount && newSteps[index + 1].nodeType === NodeTypes_1.NodeTypes.STEP_AND) {
                        let nextStep = newSteps[index + 1];
                        // Make it a GIVEN step
                        nextStep.nodeType = NodeTypes_1.NodeTypes.STEP_GIVEN;
                        // Change the sentence content!
                        if (!!nextStep.content) {
                            const stepAndKeyword = (keywords.stepAnd || ['and'])[0];
                            const stepGivenKeyword = (keywords.stepGiven || ['given'])[0];
                            const regex = new RegExp(stepAndKeyword, 'i');
                            nextStep.content = nextStep.content.replace(regex, CaseConversor_1.convertCase(stepGivenKeyword, CaseType_1.CaseType.PASCAL)); // Given ...
                        }
                    }
                    ++preconditionCount;
                }
github breuerfelix / instapy-gui / src / sites / configuration / cards / jobs.jsx View on Github external
moveJob = async (job, direction) => {
		// TODO only move job if ALL jobs are valid !!
		// TODO otherwise some garbage data might be saved into those variables
		// TODO or make a new endpoint which only moves the job, and does only change the pos

		const { jobs } = this.state;
		const idx = jobs.findIndex(x => x._id.$oid == job._id.$oid);

		if (idx == -1) raiseError('could not locate job: ' + job);

		arrayMove.mut(jobs, idx, idx + direction);
		this.setState({ jobs });

		// update all jobs since positioning changed
		const updated_jobs = await ConfigService.updateJobs(jobs);
		this.setJobs(updated_jobs);
	}
github breuerfelix / king-bot-api / frontend / features / building_queue.jsx View on Github external
move_down = building => {
		const queues = this.state.queue;
		var idx = queues.indexOf(building);
		if (idx != -1) {
			arrayMove.mut(queues, idx, idx + 1); // The second parameter is the number of elements to remove.
		}

		this.setState({ queue: [ ...queues ] });
	}
github breuerfelix / king-bot-api / frontend / features / building_queue.jsx View on Github external
move_up = building => {
		const queues = this.state.queue;
		var idx = queues.indexOf(building);
		if (idx != -1) {
			arrayMove.mut(queues, idx, idx - 1); // The second parameter is the number of elements to remove.
		}

		this.setState({ queue: [ ...queues ] });
	}
github yoshuawuyts / microcomponent / example.js View on Github external
down: function () {
      var idx = state.posts.indexOf(post)
      move(state.posts, idx, idx + 1)
      update()
    },
    first: function () {
github yoshuawuyts / microcomponent / example.js View on Github external
up: function () {
      var idx = state.posts.indexOf(post)
      move(state.posts, idx, idx - 1)
      update()
    },
    down: function () {

array-move

Move an array item to a different position

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis

Popular array-move functions