From 6ce60a79aa9eb28367b7d4d46eda714bf690c1ef Mon Sep 17 00:00:00 2001 From: Nicolas Bossard Date: Fri, 12 Jan 2024 17:03:16 +0100 Subject: [PATCH] adding support of numbers --- CHANGELOG.md | 2 ++ cycle.test.ts | 6 ++++++ cycle.ts | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ca5361..7c415ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ ## [1.0.7] - 2024-0X-XX +- adding support of numbers + ## [1.0.6] - 2024-01-10 ### Changed diff --git a/cycle.test.ts b/cycle.test.ts index fe86429..caaa941 100644 --- a/cycle.test.ts +++ b/cycle.test.ts @@ -7,6 +7,12 @@ let cycles= [ ] describe('findCycle function', () => { + it('should return the next number if current word is a number', () => { + expect(findCycle('1', 1, cycles)).toBe('2'); + expect(findCycle('7', 1, cycles)).toBe('8'); + expect(findCycle('7', -1, cycles)).toBe('6'); + }); + it('should return the next word in the cycle when going up', () => { expect(findCycle('Lundi', 1, cycles)).toBe('Mardi'); expect(findCycle('Vendredi', 1, cycles)).toBe('Samedi'); diff --git a/cycle.ts b/cycle.ts index 0ce14e3..d401159 100644 --- a/cycle.ts +++ b/cycle.ts @@ -16,6 +16,12 @@ export function findCycle(parCurWord: string, parDirection: number, parCycles: s let curCycleIndex: number; let curCycleWordIndex: number; + // checking if it is a number + if (!isNaN(Number(parCurWord))) { + return String(Number(parCurWord) + parDirection); + } + + // searching in all cycles for (let i = 0; i < parCycles.length; i++) { curCycle = parCycles[i]; curCycleIndex = curCycle.indexOf(parCurWord);