原创 Ruby Array and .max

I'm very confused here. Why does ["4", "5", "29", "54", "4", "0", "-214", "542", "-64", "1", "-3", "6", "-6"].max r

原创 How to combine the value of multiple hashes within an array by the same key

I have an array of hashes like so: [{"apple"=>5}, {"banana"=>4}, {"orange"=>6}, {"apple"=>4}, {"orange"=>2}] How I do

原创 Sorting array elements by date

dates = ["6/23/2014", "8/5/2014", "8/19/2014", "6/26/2014", "8/19/2014", "8/19/2014", "7/8/2014", "6/3/2014"

原创 Ruby: how to sort array of string parsing the content

Here is my problem: I have an array of string which contains data like that: array = ["{109}{08} OK", "{98} T

原创 Slicing discontinuous data into continuous parts in Ruby

I have this discontinuous array: a = [1, 2, 3, 7, 8, 10, 11, 12] I need it to be an array of continuous arrays: [[1,

原创 奇偶歸一猜想

奇偶歸一猜想(英語:Collatz conjecture),是指對於每一個正整數,如果它是奇數,則對它乘3再加1,如果它是偶數,則對它除以2,如此循環,最終都能夠得到1。 如n = 6,根據上述數式,得出序列6, 3, 10, 5, 1

原创 building an array from several ranges

[*70..89, *184..193, *224..233, *296..304, *336..345] Result: [70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,

原创 Sort an Array Mixed With Integers and Strings - Ruby

I have an array that must be sorted with low number to high number and then alphabetical order. Must use Array#sort_by

原创 using an enumerable built-in Ruby to access and manipulate nested data

array = [5, 10, [15, 20], 25, [30, 35, 40] array#method { #block that adds 5} => [10, 15, [20, 25], 30, [35, 40, 45] Yo

原创 How to format strings in an array in ruby?

array = [ [0] "Bonk Radek S Male Green 6/3/1978", [1] "Bouillon Francis G Male Blue 6/3/1975", [2] "Smith St

原创 How do I sort an integer array while also keeping identical elements apart from each other?

Given this array: [38, 38, 40, 40, 40, 41, 41, 41, 41, 60] How do I sort it into this? [38, 40, 41, 60, 38, 40, 41,

原创 Extracting Data from array of hashes Ruby

Given that I have the following array of hashes @response = { "0"=>{"forename_1"=>"John", "surname_1"=>"Smith"},

原创 Finding sum of every combination of two numbers in an array in Ruby

I'm trying to create a function that checks if two numbers within an array have a sum of zero. [1,2,3,4,5] => false [1

原创 數字字母混合排序

a = ['1', '10', '100', '2', '42', 'hello', 'x1', 'x20', 'x100', '42x', '42y', '10.1.2', '10.10.2', '10.8.2'] a.map {|i|

原创 Get max consecutive occurrences of value in array

Is there a more elegant way to achieve this below: Input: array = [1, 1, 1, 0, 0, 1, 1, 1, 1, 0] Output: 4 -------