Skip to content

Commit

Permalink
chore(parse): Improve backward compatibility
Browse files Browse the repository at this point in the history
Avoid using Set and Array.from to maximize compatibility.
  • Loading branch information
danielrbradley committed Nov 11, 2020
1 parent 1eed25b commit 91ca223
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ const fieldsConfig: FieldConfig[] = [
{ name: "Year", min: 1970, max: 3000, adjustment: 0, names: {} },
];

function uniq<T>(source: T[]): T[] {
const target = [];
for (const item of source) {
if (target.indexOf(item) < 0) {
target.push(item);
}
}
return target;
}

function parseField(input: string, field: Field): number[] | undefined {
if (input === "*") return undefined;
const config = fieldsConfig[field];
Expand Down Expand Up @@ -103,9 +113,7 @@ function parseField(input: string, field: Field): number[] | undefined {
return range;
}

return Array.from(new Set(input.split(",").map(parseValue))).sort(
(a, b) => a - b
);
return uniq(input.split(",").map(parseValue)).sort((a, b) => a - b);
}

/**
Expand Down

0 comments on commit 91ca223

Please sign in to comment.