其他分享
首页 > 其他分享> > [Algorithm] Find The Vowels

[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);
});

 

标签:used,Algorithm,Vowels,vowels,number,returns,expect,test,Find
来源: https://www.cnblogs.com/Answer1215/p/11067274.html