0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

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.
This commit is contained in:
Linus Unnebäck 2020-05-15 19:53:23 +01:00 committed by GitHub
parent 89fe81168e
commit 8228ea85fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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";