1.0.5 • Published 4 years ago

@pelevesque/remove-offsets v1.0.5

Weekly downloads
9
License
MIT
Repository
github
Last release
4 years ago

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'
]
*/
1.0.5

4 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.1.0

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago