Miss any of our Open RFC calls?Watch the recordings here! »

@pelevesque/remove-offsets

1.0.5 • Public • Published

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

Command Description
npm test or npm run test All Tests Below
npm run cover Standard Style
npm run standard Coverage
npm run unit Unit 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'
]
*/

Install

npm i @pelevesque/remove-offsets

DownloadsWeekly Downloads

12

Version

1.0.5

License

MIT

Unpacked Size

8.97 kB

Total Files

6

Last publish

Collaborators

  • avatar