https://github.com/cuppilekkia/array-flattener
https://github.com/cuppilekkia/array-flattener
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/cuppilekkia/array-flattener
- Owner: cuppilekkia
- Created: 2022-08-14T10:40:01.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-14T10:40:31.000Z (almost 3 years ago)
- Last Synced: 2025-02-02T09:33:25.838Z (4 months ago)
- Language: TypeScript
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Part 1 – Flattening an array
⏱ We estimate that this should take approximately 30 minutes, but please take as much or as little time as you need.
Write an algorithm to flatten an arbitrarily nested array of values.
```
[ 1, [ 2, [ 3 ] ], 4 ] -> [ 1, 2, 3, 4 ]
```If your language of choice includes a flattening function, please implement your own.
# Solution
Install the dependencies:
```sh
npm i
```The algorithm is implemented in `src/index.ts`
## Example
An implementation example is in `src/example.ts` and it can be run with the command:
```sh
npm run start
```## Test suite
The complete test suite is in `test/index.spec.ts`.
Run all the tests with:
```sh
npm test
```