[nil, 'apple', 'orange', '', 'banana'].reject(&:blank?)
=> ["apple", "orange", "banana"]
a = [3, 2, 4, 6, 3, 8]
a.delete(3)
# A simple example function, which returns a value or nil
def transform(n)
rand > 0.5 ? n * 10 : nil }
end
items.map! { |x| transform(x) } # [1, 2, 3, 4, 5] => [10, nil, 30, 40, nil]
items.reject! { |x| x.nil? } # [10, nil, 30, 40, nil] => [10, 30, 40]
# Altering the array:
a = [3, 2, 4, 6, 3, 8]
a.delete(3)
#=> 3
a
#=> [2, 4, 6, 8]
# Creating new array:
b = [3, 2, 4, 6, 3, 8]
b - [3]
#=> [2, 4, 6, 8]
b
#=> [3, 2, 4, 6, 3, 8]
[nil, 'apple', 'orange', '', 'banana'].compact
=> ["apple", "orange", "", "banana"]
Code Example |
---|
Ruby :: ruby in array |
Ruby :: ! in ruby |
Ruby :: ruby coding challenges |
Ruby :: convert ruby hash to json string |
Ruby :: rails edit models |
Ruby :: ||= ruby |
Ruby :: ruby array of symbols |
Ruby :: ruby rspec change matcher |
Ruby :: my rails server exits automatically and now gives the following error: |
Ruby :: rails change reference |
Ruby :: ruby on rails freecodecamp |
Ruby :: start times from 1 in ruby |
Ruby :: common functions in rails |
Ruby :: class inheriting multiple modules in ruby |
Ruby :: rails partial check if local exists |
Ruby :: logstash-logger gem |
Ruby :: ruby decode base64 |
Ruby :: division in ruby |
R :: how to fill na values in r |
R :: r loops |
R :: multiple intersect r |
R :: set row names in r |
R :: import excel into r |
R :: remove row from matrix r |
R :: R remove commas |
R :: geom_point r |
R :: find nas in dataframe r |
R :: open xlsx with r |
R :: switch to another line in string r |
R :: cbind vectors of different lengths r |