Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including @pelevesque/remove-offsets with all npm packages installed. Try it out:

var removeOffsets = require("@pelevesque/remove-offsets")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@pelevesque/remove-offsets v1.0.5

Removes and returns offsetted strings from an array.

Build Status Coverage Status JavaScript Style Guide

remove-offsets

Removes and returns offsetted strings from an array.

Node Repository

https://www.npmjs.com/package/@pelevesque/remove-offsets

Installation

npm install @pelevesque/remove-offsets

Tests

CommandDescription
npm test or npm run testAll Tests Below
npm run coverStandard Style
npm run standardCoverage
npm run unitUnit Tests

Usage

Parameters

arr     (required)
options (optional) default = { step: 1, remove: true }

Requiring

const removeOffsets = require('@pelevesque/remove-offsets')

Basic

const arr = [
  'abcdef',
  '123456',
  'defabc', // 0
  'apple',
  '234561', // 1
  'banana',
  '456123', // 1
  'panama',
  'amapan' // 7
]
const offsets = removeOffsets(arr)
/*
arr = [
  'abcdef',
  '123456',
  'apple',
  'banana',
  'panama'
]
offsets = [
  'defabc',
  '234561',
  '456123',
  'amapan'
]
*/

Step Option

// Only check for offsets every 4 steps
const arr = [
  '123456789',
  'aaaabbbbb',
  'abbbbbaaa',
  'bbbbbaaaa', // 1
  '234567891', // 0
  '678912345', // 0
  '912345678'
]
const offsets = removeOffsets(arr, { step: 4 })
/*
arr = [
  '123456789',
  'aaaabbbbb',
  'abbbbbaaa',
  '912345678'
]
offsets = [
  'bbbbbaaaa',
  '234567891',
  '678912345'
]
*/

Remove Option

With the remove option set to false, offsets are still returned, but nothing is removed from the original array.

// Only check for offsets every 4 steps
const arr = [
  '123456789',
  'aaaabbbbb',
  'abbbbbaaa',
  'bbbbbaaaa', // 1
  '234567891', // 0
  '678912345', // 0
  '912345678'
]
const offsets = removeOffsets(arr, { step: 4, remove: false })
/*
arr = [
  '123456789',
  'aaaabbbbb',
  'abbbbbaaa',
  'bbbbbaaaa',
  '234567891',
  '678912345',
  '912345678'
]
offsets = [
  'bbbbbaaaa',
  '234567891',
  '678912345'
]
*/
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free