gistlib
other ruby categories
array code snippets in ruby
250741 is what i want to convert to an int array in ruby
add an element to the beginning of an array in ruby
create a function that appends text to a string from an input array in ruby
create a matrix in ruby
create an array with every book of the bible in it in ruby
example of a function that takes only the first two elements of an array and joins their indexes as an integer in ruby
explain `.sum(0, &cols.method(:[])).to_i` in ruby
explain `e = (1..3).chain([4, 5]) e.to_a #=> [1, 2, 3, 4, 5]` in ruby
find the average of all elements in an array in ruby
find the first element in an array in ruby
find the greatest common divisor of a list of numbers in ruby
find the kth largest number in a list in ruby
find the kth least common element in an array in ruby
find the kth least frequent element in an array in ruby
find the kth most frequent element in an array in ruby
find the kth smallest number in a list in ruby
find the largest element in an array in ruby
find the least common multiple of a list of numbers in ruby
find the mode of all elements in an array in ruby
find the range of a list of numbers in ruby
find the sum of all elements in an array in ruby
find the variance of a list of numbers in ruby
fix this: class flattenarray def self.flatten(ar) return [] if ar.all?(&:nil?) ar.compact! if ar.include?(nil) ar.flatten end end in ruby
for this array: [{p:10, n:"m", size: {s: 7, m: 2}} how to display only the 'size'? in ruby
generate a random array in ruby
get a random element from an array in ruby
get a sample of 5 elements from an array with replacement in ruby
give swift version for: pets.map { |pet| pet[:names].select { |name| name.length <= 5 } }.flatten.sort in ruby
how do i add these two element-wise so the result is another 3-element array? [*1..3] + [*4..6] in ruby
how to change `cols = %w(black, brown, red)` to this: `cols = { "black" => '0', "brown" => '1', "red" => '2'}` in ruby
how to fix? `[1, 10, 100].map(&:prod * 3)` in ruby
how to return the total value of all the hash values of three hashes, each of which is an element of an array using map or some shorter code? in ruby
how to select first two elements of an array and loop over them? in ruby
how to sum this if the hash is inside an array? [{ a: 5, b: 10, c: 15 }] in ruby
how to use [1..4] to generate an array in ruby
i have an array [1,2,3]. and my input to function arg is n. if n is either 1 or 2 or 3, do sth. if n is a number not in that array, do sth else. give me the code. in ruby
i have an array with 3 elements, each is a hash. how to print the third hash? in ruby
is there a to_array methd? in ruby
iterate over a list in ruby
join an array of characters into a string in ruby
select from an array whose elements are hashes in ruby
select the first two elements of an array, loop over them such that their index numbers become digits (like 01) in ruby
several ways to swap elements in [1, 2]? in ruby
sort an array in ruby
split a string into an array of characters in ruby
split a string into an array of words in ruby
what does it mean `[nil, true, 99].all? ` in ruby
what to do in order to get ["0", "[0, 1], "{foo: 0}"] in ruby
gistlib
by LogSnag