[Algorithm] Find The Vowels
2024-09-05 06:07:19
// --- 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);
});
最新文章
- 利用xinetd进行时间同步
- SAP中需要记住的一些标准表
- C#图像处理
- libsvm Minist Hog 手写体识别
- [git]解决:git config --global push.default matching
- 用cryptico.js实现RSA加密(应对cryptico不支持PEM)
- gulp browser-sync自动刷新插件
- nginx 请求负载 转发规则设置
- 《4》CentOS7.0+OpenStack+kvm云平台部署—配置Nova
- Navicat连接oracle,出现Only compatible with oci version 8.1 and&;amp;nb
- hdu 4507 数位dp(求和,求平方和)
- iOS有关图片处理的总结 (四)------图片的饱和度,亮度,对照度。
- C/C++知识点清单02-上
- 用mongo和redis查询排行榜、统计活跃用户
- Windows10 永久激活查询/激活时间查询/激活查询命令/激活码查询
- echarts柱状图Demo
- 一个简单文本分类任务-EM算法-R语言
- 【bzoj4066】 简单题
- 删除map、list集合元素总结
- js布尔值转化