From 8228ea85fd610d5496a3240538f15d2f4eed1d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20Unneb=C3=A4ck?= Date: Fri, 15 May 2020 19:53:23 +0100 Subject: refactor(fs): use every instead of reduce (#5323) The previous usage of `reduce` was basically implementing the `every` A small difference is that the new implementation will stop checking as soon as one element have returned false, which will reduce the number of unnecessary checks. --- std/fs/_util.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'std/fs') diff --git a/std/fs/_util.ts b/std/fs/_util.ts index aecd9748b..bae48c970 100644 --- a/std/fs/_util.ts +++ b/std/fs/_util.ts @@ -16,11 +16,7 @@ export function isSubdir( } const srcArray = src.split(sep); const destArray = dest.split(sep); - // see: https://github.com/Microsoft/TypeScript/issues/30821 - // @ts-ignore - return srcArray.reduce((acc: true, current: string, i: number): boolean => { - return acc && destArray[i] === current; - }, true); + return srcArray.every((current, i) => destArray[i] === current); } export type PathType = "file" | "dir" | "symlink"; -- cgit v1.2.3