[Algorithm] Find The Vowels
Posted answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Algorithm] Find The Vowels相关的知识,希望对你有一定的参考价值。
// --- Directions// Write a function that returns the number of vowels// used in a string. Vowels are the characters ‘a‘, ‘e‘// ‘i‘, ‘o‘, and ‘u‘.// --- Examples// vowels(‘Hi There!‘) --> 3// vowels(‘Why do you ask?‘) --> 4// vowels(‘Why?‘) --> 0
function vowels(str) const matchs = str.match(/[aeiou]/gi); return matchs ? matchs.length : 0; module.exports = vowels;
const vowels = require(‘./index‘); test(‘Vowels is a function‘, () => expect(typeof vowels).toEqual(‘function‘); ); test(‘returns the number of vowels used‘, () => expect(vowels(‘aeiou‘)).toEqual(5); ); test(‘returns the number of vowels used when they are capitalized‘, () => expect(vowels(‘AEIOU‘)).toEqual(5); ); test(‘returns the number of vowels used‘, () => expect(vowels(‘abcdefghijklmnopqrstuvwxyz‘)).toEqual(5); ); test(‘returns the number of vowels used‘, () => expect(vowels(‘bcdfghjkl‘)).toEqual(0); );
以上是关于[Algorithm] Find The Vowels的主要内容,如果未能解决你的问题,请参考以下文章