Ruby Count Array objects if object includes value
来源:互联网 发布:厂家销售软件 编辑:程序博客网 时间:2024/05/21 07:58
I have an array:
array = ['Footballs','Baseball','football','Soccer']
and I need to count the number of times Football or Baseball is seen, regardless of case and pluralization.
array.count { |element| element.match(/(football|baseball)s?\Z/i) }
This will match any of these elements: football, footballs, baseball, baseballs.
The s?
makes the 's' optional, the i
option (//i
) makes the expression case insensitive, and the\Z
option checks for the end of the string.
0 0
- Ruby Count Array objects if object includes value
- Ruby array repeat value if next not present
- how to sort array in ruby if i have nil object inside array?
- Convert array of key value object to object of the key values (ruby)
- Check if object is array?
- Ruby: Sorting an array of strings, in alphabetical order, that includes some arrays of strings
- Array objects
- ES2016系列: Array.prototype.includes
- Ruby: Count unique elements and their occurences in an array
- Checking if an array contains a value in C#
- iOS-报错[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
- NSCFConstantString countByEate:objects:count:
- Merge array and hash in ruby if key appears in array
- ruby array
- Ruby Array
- INCLUDES
- includes
- includes
- 设计模式之装饰模式
- 下载Android源代码错误汇总分析
- unity 消息分发
- C语言中连接器介绍
- ”该硬盘处于脱机.因为他与另一个联机磁盘发生签名冲突“的解决方法,有图有真相
- Ruby Count Array objects if object includes value
- 监听套接字 连接套接字
- 杭电OJ(HDU)-ACMSteps-Chapter Three-《FatMouse' Trade》《今年暑假不AC》《排名》《开门人和关门人》
- Linux常用命令
- poj 4001 抓住那头牛 (广度优先搜索算法)
- Swift 易忽略的笔记 2):String
- openvz 创建
- tomcat下解决 iOS7.1企业应用"无法安装应用程序 因为证书无效"的问题
- linux下eclipse配置jdk