https://github.com/forcir/subsequences
Easily generate subsequences from a provided map, array, or string input.
https://github.com/forcir/subsequences
subarray subarrays subsequence subsequences subset subsets
Last synced: 8 months ago
JSON representation
Easily generate subsequences from a provided map, array, or string input.
- Host: GitHub
- URL: https://github.com/forcir/subsequences
- Owner: forcir
- License: mit
- Created: 2023-07-12T03:56:45.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-14T03:22:31.000Z (over 2 years ago)
- Last Synced: 2025-04-18T03:34:30.801Z (8 months ago)
- Topics: subarray, subarrays, subsequence, subsequences, subset, subsets
- Language: TypeScript
- Homepage: https://npmjs.com/subsequences
- Size: 88.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
Easily generate subsequences from a provided map, array, or string input.
> A subsequence is a sequence that can be derived from another sequence by removing zero or more elements, without changing the order of the remaining elements.
## Install
```bash
pnpm add subsequences
```
```bash
yarn add subsequences
```
```bash
npm install subsequences
```
## Basic Usage
```ts
import { Subsequence } from "subsequences";
```
### Generate subsequence from Array
```ts
const subsequences = Subsequence.fromArray(["1", "2", "3", "4"]);
console.log({ subsequences });
```
Output
```json
{
"subsequences": [
["1", "2", "3", "4"],
["1", "2", "3"],
["1", "2", "4"],
["1", "2"],
["1", "3", "4"],
["1", "3"],
["1", "4"],
["1"],
["2", "3", "4"],
["2", "3"],
["2", "4"],
["2"],
["3", "4"],
["3"],
["4"]
]
}
```
### Generate subsequence from String
```ts
const subsequences = Subsequence.fromString("1234");
console.log({ subsequences });
```
Output
```json
{
"subsequences": [
["1", "2", "3", "4"],
["1", "2", "3"],
["1", "2", "4"],
["1", "2"],
["1", "3", "4"],
["1", "3"],
["1", "4"],
["1"],
["2", "3", "4"],
["2", "3"],
["2", "4"],
["2"],
["3", "4"],
["3"],
["4"]
]
}
```
## Advanced Usage
### Instantiate with Map (Key/Value Pairs)
```ts
import { Subsequence } from "subsequences";
const subsequences = new Subsequence([
["first", "1"],
["second", "2"],
["third", "3"],
["fourth", "4"],
]);
console.log(subsequences.entrySubsequences);
console.log(subsequences.i18nSubsequences);
console.log(subsequences.keySubsequences);
console.log(subsequences.valueSubsequences);
```
entrySubsequences output
```json
[
["first_1", "second_2", "third_3", "fourth_4"],
["first_1", "second_2", "third_3"],
["first_1", "second_2", "fourth_4"],
["first_1", "second_2"],
["first_1", "third_3", "fourth_4"],
["first_1", "third_3"],
["first_1", "fourth_4"],
["first_1"],
["second_2", "third_3", "fourth_4"],
["second_2", "third_3"],
["second_2", "fourth_4"],
["second_2"],
["third_3", "fourth_4"],
["third_3"],
["fourth_4"]
]
```
i18nSubsequences output
```json
[
{
"key": "first1_second2_third3_fourth4",
"values": { "first": "1", "second": "2", "third": "3", "fourth": "4" }
},
{
"key": "first1_second2_third3",
"values": { "first": "1", "second": "2", "third": "3" }
},
{
"key": "first1_second2_fourth4",
"values": { "first": "1", "second": "2", "fourth": "4" }
},
{ "key": "first1_second2", "values": { "first": "1", "second": "2" } },
{
"key": "first1_third3_fourth4",
"values": { "first": "1", "third": "3", "fourth": "4" }
},
{ "key": "first1_third3", "values": { "first": "1", "third": "3" } },
{ "key": "first1_fourth4", "values": { "first": "1", "fourth": "4" } },
{ "key": "first1", "values": { "first": "1" } },
{
"key": "second2_third3_fourth4",
"values": { "second": "2", "third": "3", "fourth": "4" }
},
{ "key": "second2_third3", "values": { "second": "2", "third": "3" } },
{ "key": "second2_fourth4", "values": { "second": "2", "fourth": "4" } },
{ "key": "second2", "values": { "second": "2" } },
{ "key": "third3_fourth4", "values": { "third": "3", "fourth": "4" } },
{ "key": "third3", "values": { "third": "3" } },
{ "key": "fourth4", "values": { "fourth": "4" } }
]
```
keySubsequences output
```json
[
["first", "second", "third", "fourth"],
["first", "second", "third"],
["first", "second", "fourth"],
["first", "second"],
["first", "third", "fourth"],
["first", "third"],
["first", "fourth"],
["first"],
["second", "third", "fourth"],
["second", "third"],
["second", "fourth"],
["second"],
["third", "fourth"],
["third"],
["fourth"]
]
```
valueSubsequences output
```json
[
["1", "2", "3", "4"],
["1", "2", "3"],
["1", "2", "4"],
["1", "2"],
["1", "3", "4"],
["1", "3"],
["1", "4"],
["1"],
["2", "3", "4"],
["2", "3"],
["2", "4"],
["2"],
["3", "4"],
["3"],
["4"]
]
```