Skip to content

Commit

Permalink
feat: update utils lib
Browse files Browse the repository at this point in the history
* Use generic types (`<T>`) instead `any`
* Remove unused hash generation function
  • Loading branch information
mateusfg7 committed Dec 2, 2022
1 parent 6cff472 commit 7e86f49
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import md5 from 'blueimp-md5'

export const getFrequencyOfValue = (array: any[], value: unknown): number => {
export function getFrequencyOfValue<T>(array: T[], value: unknown): number {
let frequency = 0

array.forEach(element => (element === value ? frequency++ : null))

return frequency
}

export const removeRepeatedValuesFromArray = (array: any[]): any[] => {
export function removeRepeatedValuesFromArray<T>(array: T[]): T[] {
return array.filter((item, index, originalArray) => {
return originalArray.indexOf(item) === index
})
}

export function getHashHeaderOfData(data: string | number): string {
const hash = md5(data.toString())
const hashHeader = hash.substring(0, hash.length / 2)

return hashHeader
}

0 comments on commit 7e86f49

Please sign in to comment.