Created
November 11, 2010 17:30
-
-
Save yoggy/672854 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/ruby | |
require 'pp' | |
a = [ | |
[1,2,3], | |
[4,5,6], | |
[7,8,9] | |
] | |
b = { | |
1 => [2, 3], | |
4 => [5, 6], | |
7 => [8, 9] | |
} | |
# 配列だけのばあい | |
(1..9).each{|i| | |
is_find = false | |
a.each {|c| | |
is_find = true if c[0] == i | |
} | |
unless is_find | |
a << [i, 0, 0] | |
end | |
} | |
# ハッシュを使う場合 | |
(1..9).each{|i| | |
unless b.key?(i) | |
b[i] = [0, 0] | |
end | |
} | |
pp a | |
pp b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment