zoukankan      html  css  js  c++  java
  • [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);
    });
  • 相关阅读:
    如何用vue做计算器功能
    js反弹运动
    $.each的使用
    js文字滚动事件
    根据服务器时间,计算出时间轴的倒计时。
    时间格式转时间戳的几种方法
    匀速运动升级
    js匀速运动
    js图片滚动无缝衔接
    webFrame
  • 原文地址:https://www.cnblogs.com/Answer1215/p/11067274.html
Copyright © 2011-2022 走看看