@bemoje/arr-swap

Swap array elements in place. Runtime: O(1)

Usage no npm install needed!

<script type="module">
  import bemojeArrSwap from 'https://cdn.skypack.dev/@bemoje/arr-swap';
</script>

README

@bemoje/arr-swap

Swap array elements in place. Runtime: O(1)

Version

NPM version

Travis CI

dependencies

Dependencies

dependencies

Stats

NPM downloads Forks

Donate

Buy Me A Beer donate button PayPal donate button

Installation

npm install @bemoje/arr-swap
npm install --save @bemoje/arr-swap
npm install --save-dev @bemoje/arr-swap

Usage

import arrSwap from '@bemoje/arr-swap'

const arr = [10, 20]

arrSwap(arr, 0, 1)

console.log(arr)
//=> [20, 10]

Tests

Uses Jest to test module functionality. Run tests to get coverage details.

npm run test

API

arrSwap

Swap array elements in place. Runtime: O(1)

Parameters
  • arr array to be modified

  • from number index of the first element

  • to number index of the 2nd element

Returns

void