Skip to content

Commit

Permalink
🐛 fix negative ranges on formatToHiddenDigits
Browse files Browse the repository at this point in the history
  • Loading branch information
VitorLuizC committed Jun 10, 2023
1 parent 041441c commit d16a688
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/models/Range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const normalizeRange = (

if (range >= 0) return [0, range];

return [limit - Math.abs(range), limit];
return [limit + 1 - Math.abs(range), limit];
};

export const within = (
Expand Down
26 changes: 14 additions & 12 deletions src/parsers/parseToCharacters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@ export type RootCharacterNode = {
const parseToCharacters = (value: string): RootCharacterNode => {
let digits = 0;

const children = value.split('').map((character: string): DigitCharacterNode | OtherCharacterNode => {
if (DIGIT.test(character))
return {
character,
kind: 'digit',
digit: ++digits, // It returns the incremented value of 'digits'.
};
return {
character,
kind: 'other',
};
});

return {
digits,
children,
kind: 'root',
children: value.split('').map((character, index) =>
DIGIT.test(character)
? {
character,
kind: 'digit',
digit: ++digits, // It returns the incremented value of 'digits'.
}
: {
character,
kind: 'other',
}
),
};
};

Expand Down

0 comments on commit d16a688

Please sign in to comment.