首页 > 其他 > 详细

[Algorithm] Find The Vowels

时间:2019-06-21 23:48:28      阅读:196      评论:0      收藏:0      [点我收藏+]

 

// --- 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

原文:https://www.cnblogs.com/Answer1215/p/11067274.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!