Skip to content

Instantly share code, notes, and snippets.

View AlanJereb's full-sized avatar

Alan Jereb AlanJereb

View GitHub Profile
@AlanJereb
AlanJereb / ForEach_Map_Filter_using_Reduce.ts
Last active August 23, 2023 07:19
ForEach, Filter and Map implemented using Reduce [typesafe]
const testArray = [1, 2, 3];
// ----
// MAP
// ----
const customMap = <T extends unknown>(arr: T[], callback: (value: T) => T) => {
return arr.reduce((mapped: T[], current) => {
mapped.push(callback(current))
return mapped
}, [])
}