(Before start, I am using Ruby 1.8.7, so I won't be able to use fancy stuff.)
As title says, I want to calculate the average of column or row.
But, I can't even find the way to traverse/iterate Matrix form of array from online.
Let's say you have…
I have the following regex pattern:
(?:http.?:\/\/)
This matches the protocol component from a web url, I want a regex to do the opposit, to match everything except the protocol, so far my every attempt has not worked at all.
Becuase ultimatly what…
I am trying to do some calculation like the following. option is an empty hash and aes is an array.
options = {}
aes = [1,2]
test = aes.inject([]) do |array, value|
array << value + 2
array << value -1 if options[:calculation] # here…
I have a list of k artistes mapped to their respective music videos that they have starred in. This is represented in a multidimensional array:
musicvid_arr =
[["MUSICVID 1", 2014, ["ARTISTE 1", "ARTISTE 2", "ARTISTE 3"]],
["MUSICVID 2", 2014,…
Say, I have an array:
a = [1,2]
and
n = 3
I want output like this:
[[1, 1, 1], [1, 1, 2], [1, 2, 1], [1, 2, 2], [2, 1, 1], [2, 1, 2], [2, 2, 1], [2, 2, 2]]
This are all possible combinations of length n of elements from array a.
Most importantly…
I usually sort ruby hashes using the very famous sort method as given in my example below. But this terribly fails when the string key has an underscore in it. For eg:
h = {"b" => 1, "a" => 2}
Hash[h.sort]
sorts the hash perfectly. But when the…
I want to add new table using rails migration:
**table_name** users_location_track
**columns** id (primary key, auto increment serial),
user_id (reference to users), location_info (string),
creation_time(time-stamp)
please…