polkadot-js/api

View on GitHub
packages/types/src/metadata/util/flattenUniq.spec.ts

Summary

Maintainability
A
0 mins
Test Coverage
// Copyright 2017-2024 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0

/// <reference types="@polkadot/dev-test/globals.d.ts" />

import { flattenUniq } from './index.js';

describe('flattenUniq', (): void => {
  it('flattens nested arrays', (): void => {
    expect(
      flattenUniq(['a', ['b', ['c', 'd', ['e']]], [['f', 'g']]])
    ).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g']);
  });

  it('flattens nested arrays, removing duplicated', (): void => {
    expect(
      flattenUniq(['a', 'b', ['b', ['b', 'c', 'd', ['e'], 'f', 'g']], ['c', ['f', 'g']]])
    ).toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g']);
  });
});