Getting the indexes of duplicate elements in arrays (Ruby)
来源:互联网 发布:数据挖掘导论百度云 编辑:程序博客网 时间:2024/06/10 22:44
I have an array in Ruby that has some duplicate elements. E.g.:
fruits = ["apples", "bananas", "apples", "grapes", "apples"]
-------------------------------------------------------------------
fruits.to_enum.with_index.select{|e, _| e == "apples"}.map(&:last)
fruits.each_index.select { |i| fruits[i]=="apples" }
fruits.each_with_index.select{|v, i| v == "apples"}.map(&:last)
0 0
- Getting the indexes of duplicate elements in arrays (Ruby)
- P14 (*) Duplicate the elements of a list.
- P14 (*) -P15 (**)Duplicate the elements of a list,Duplicate the elements of a list a given number of
- Getting the Hostname or IP in Ruby on Rails
- Whats the best way to split an array in ruby into multiple smaller arrays of random size
- List the maximum or minimum of the elements at each position of two arrays
- Tricks in decide the index in the binary search with duplicate elements
- Ruby Arrays: keep repeated values only from the end of an array of arrays
- Give an O(lg n)-time algorithm to find the median of all 2n elements in arrays X and Y.
- Getting over the dangers of rm command in Linux---reference
- Matching Portions of A String to Elements of an Array in Ruby
- The Elements of Style
- The Elements of Style
- The Elements of Style
- Find the two non-repeating elements in an array of repeating elements
- Remove duplicate elements in an array
- Ruby: Sorting an array of strings, in alphabetical order, that includes some arrays of strings
- Find common elements in three sorted arrays
- DevGridControl单元格背景色和单元格文字颜色设置
- javascript 加密/解密 (比如youtube的leanback网站)
- WaitForSingleObject函数的使用
- node.js中关于使用formidable模块实现文件上传至指定目录的问题
- 分类搜索
- Getting the indexes of duplicate elements in arrays (Ruby)
- 锋利的JQuery 第四章后续部分
- 堆和栈的区别
- android equalsIgnoreCase和equals的比较说明
- android 监控软键盘确定 搜索 按钮并赋予点击事件
- shell脚本if判断语句报错[: too many arguments的两种原因
- 黑马程序员---OC Prorocol代理模式
- Js的Url中传递中文参数乱码,如何获取Url中参数问题
- 用jquery 绑定一个按钮click事件后,第一次点击后,一切正常,第二次点击,竟然执行两次,以后越来越多