Socket
Socket
Sign inDemoInstall

array-to-string-transformer

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    array-to-string-transformer

``` [1,2,3,4,5,6,7,8] -> "1-8" [1,3,4,5,6,7,8] -> "1,3-8" [1,3,4,5,6,7,8,10,11,12] -> "1,3-8,10-12" [1,2,3] -> "1-3" [1,2] -> "1,2" [1,2,4] -> "1,2,4" [1,2,4,5,6] -> "1,2,4-6" [1,2,3,7,8,9,15,17,19,20,21] -> "1-3,7-9,15,17,19-21" [1,2,3,4,5,6,100,1091,199


Version published
Maintainers
1
Install size
3.32 kB
Created

Readme

Source

Преобразование массива чисел в строку

[1,2,3,4,5,6,7,8] -> "1-8"
[1,3,4,5,6,7,8] -> "1,3-8"
[1,3,4,5,6,7,8,10,11,12] -> "1,3-8,10-12"
[1,2,3] -> "1-3"
[1,2] -> "1,2"
[1,2,4] -> "1,2,4"
[1,2,4,5,6] -> "1,2,4-6"
[1,2,3,7,8,9,15,17,19,20,21] -> "1-3,7-9,15,17,19-21"
[1,2,3,4,5,6,100,1091,1999,2000,2001,2002] -> "1-6,100,1091,1999-2002"
[1] -> "1"
[1,3,5,7,9,11] -> "1,3,5,7,9,11"
  • Числа в массиве всегда целые, положительные и отсортированы по возрастанию.

Установка

npm i array-to-string-transformer

Пример использования

import arrayToStringTransformer from 'array-to-string-transformer';

(async () => {
    const range = await arrayToStringTransformer([1,2,3,4,5,6,7,8]);
    console.log(range); // 1-8
})();

Тест

npm test

FAQs

Last updated on 20 May 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc