DEV Community

Discussion on: Daily Challenge #3 - Vowel Counter

Collapse
 
valerionarcisi profile image
Valerio Narcisi • Edited

//TS

my solution with TDD:

test:

import vowelCounter from './vowel-counter';

describe('tdd vowel counter', () => {
    test('should be 0 if empty string', () => {
        expect(vowelCounter('')).toEqual(0);
    });
    test('should be return counter', () => {
        expect(vowelCounter('aWscErvO')).toEqual(3);
        expect(vowelCounter('aaaa')).toEqual(4);
        expect(vowelCounter('IIIII')).toEqual(5);
        expect(vowelCounter('AEr#_%^&tioCda')).toEqual(5);
    });
});

and func


export default (str: string): number =>
    str
        .toLowerCase()
        .split('')
        .filter(val => ['a', 'e', 'i', 'o', 'u'].includes(val)).length;