Skip to content

Commit

Permalink
refactor: move remove utility into array module
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwep committed May 1, 2024
1 parent 4ef7653 commit 7fccd43
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/app/components/charts/echart/EChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import * as echarts from 'echarts/core';
import { EChartsType } from 'echarts/core';
import { computed, onMounted, onUnmounted, ref, shallowRef, watch } from 'vue';
import { useResizeObserver } from '@composables';
import { ClassNames } from '@utils';
import { getCssVariables } from '../../../../utils/cssVariables';
import { svgToPNG } from '../../../../utils/svgToPNG';
import { ClassNames, getCssVariables, svgToPNG } from '@utils';
/* eslint-disable @typescript-eslint/no-explicit-any */
const props = defineProps<{
Expand Down
8 changes: 8 additions & 0 deletions src/utils/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ export const add = (...arrays: readonly number[][]) => {
return sum;
};

export const remove = <T>(t: T[], v: T | ((v: T) => boolean)): void => {
const index = typeof v === 'function' ? t.findIndex((tv) => (v as (v: T) => boolean)(tv)) : t.indexOf(v);

if (index !== -1) {
t.splice(index, 1);
}
};

export const sum = (values: readonly number[]) => values.reduce((a, b) => a + b, 0);

export const average = (values: readonly number[]) => sum(values) / values.length;
Expand Down
3 changes: 2 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ export * from './array';
export * from './debounce';
export * from './logger';
export * from './readFile';
export * from './remove';
export * from './downloadFile';
export * from './selectFile';
export * from './types';
export * from './uuid';
export * from './svgToPNG';
export * from './cssVariables';
4 changes: 0 additions & 4 deletions src/utils/remove.ts

This file was deleted.

0 comments on commit 7fccd43

Please sign in to comment.