From a2283ec6ddd25fccc82c3cbeb8ee3cd4e304fdb8 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 14 Mar 2018 10:04:33 -0700 Subject: [PATCH] Simplify implementation of firstOrUndefined and lastOrUndefined --- src/compiler/core.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 320f4e9f4ddc1..8f38f16c049e4 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1077,7 +1077,7 @@ namespace ts { * Returns the first element of an array if non-empty, `undefined` otherwise. */ export function firstOrUndefined(array: ReadonlyArray): T | undefined { - return elementAt(array, 0); + return array.length === 0 ? undefined : array[0]; } export function first(array: ReadonlyArray): T { @@ -1089,7 +1089,7 @@ namespace ts { * Returns the last element of an array if non-empty, `undefined` otherwise. */ export function lastOrUndefined(array: ReadonlyArray): T | undefined { - return elementAt(array, -1); + return array.length === 0 ? undefined : array[array.length - 1]; } export function last(array: ReadonlyArray): T {