Last active
September 16, 2021 17:05
-
-
Save lmsilvera/cdf6f79616773d1b46a4fe8549e467b9 to your computer and use it in GitHub Desktop.
Array and Hashes Workshop notes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Ruby 2.7.0 | |
| ar = [1,2,3,4] | |
| ar.first | |
| ar.last | |
| ar[1] | |
| ar << 5 | |
| ar.push(6) | |
| ar.map(&:to_s) | |
| ar.delete(3) | |
| ar.delete_at(2) # use index | |
| ar.unique | |
| ar.select{|n| n % 2 == 0} | |
| ar.reject{|n| n % 2 == 0} | |
| ar.include?(4) | |
| ar.sort | |
| puts ar.map{|n| n * 2 } | |
| arr.each{|n| puts n * 2 } | |
| arr.size | |
| arr.count | |
| arr.any? | |
| arr.empty? | |
| arr.compact | |
| arr.flatten | |
| arr.sum # result: 21 | |
| arr.reverse | |
| arr.sample | |
| arr.slice | |
| # Ruby 2.7 | |
| ar2 = [1,1,2] | |
| ar2.map(&:even?).tally | |
| # bang ! | |
| h = {a: 1, b: 2, c: 2} | |
| h.key?(:a) | |
| h[:a] | |
| h.to_a | |
| h.keys | |
| h.values | |
| h.size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment