This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type RemoveUndefined<T extends any[]> = | |
T extends (infer R | undefined)[] | |
? R[] | |
: T | |
// OK | |
type ArrayWithoutUndefined1 = RemoveUndefined<(string | number | undefined | Date)[]> | |
type ArrayWithoutUndefined2 = RemoveUndefined<(string | number | Date)[]> | |
type ArrayWithoutUndefined3 = RemoveUndefined<["hello", 1, 2, undefined, Date, {}]> // order is not maintained | |
type ArrayWithoutUndefined4 = RemoveUndefined<["hello", 1, 2, Date, {}]> // order is not maintained |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// const arr: number[] = [1, 3, 2, 5, 0]; | |
const findProductOfArr = (arr: number[]): number => { | |
let product: number = 1; | |
arr.forEach(num => { | |
if(num !== 0) product = product * num; | |
}); | |
return product; |