UNPKG

1.2 kBSource Map (JSON)View Raw
1{"version":3,"sources":["iterable/max.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAI5C,MAAM,UAAU,GAAG,CAAC,MAAqB,EAAE,KAAyB,QAAQ;IAC1E,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI,KAAK,GAAG,CAAC,QAAQ,CAAC;IACtB,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE;QACzB,IAAI,CAAC,WAAW,EAAE;YAChB,WAAW,GAAG,IAAI,CAAC;SACpB;QACD,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;QACnB,IAAI,CAAC,GAAG,KAAK,EAAE;YACb,KAAK,GAAG,CAAC,CAAC;SACX;KACF;IACD,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;KAClD;IAED,OAAO,KAAK,CAAC;AACf,CAAC","file":"max.js","sourcesContent":["import { identity } from '../util/identity';\n\nexport function max(source: Iterable<number>, fn?: (x: number) => number): number;\nexport function max<T>(source: Iterable<T>, fn: (x: T) => number): number;\nexport function max(source: Iterable<any>, fn: (x: any) => number = identity): number {\n let atleastOnce = false;\n let value = -Infinity;\n for (const item of source) {\n if (!atleastOnce) {\n atleastOnce = true;\n }\n const x = fn(item);\n if (x > value) {\n value = x;\n }\n }\n if (!atleastOnce) {\n throw new Error('Sequence contains no elements');\n }\n\n return value;\n}\n"]}
\No newline at end of file