V
Я вам все расклады давал)
Size: a a a
V
h
h
h
V
V
V
D
SL
V
h
V
SL
Q
РЭ
DM
DM
VV
RM
def filenames(names, index = Hash.new(0))
names.map do |name|
index[name] += 1
if index[name] == 1
name
else
new_name = "#{name}(#{index[name] - 1})"
filenames([new_name], index).first
end
end
end
names = ["photo", "photo", "doc", "photo(1)", "photo"]
puts filenames(names) # ["photo", "photo(1)", "doc", "photo(1)(1)", "photo(2)"]
def filenames(names, index = Hash.new(0))`переменную new_name не нужно вводить, если вы об этой ошибке, то нашел
names.map do |name|
index[name] += 1
if index[name] == 1
name
else
names = "#{name}(#{index[name] - 1})"
filenames([names], index).first
end
end
end
names = ["photo", "photo", "doc", "photo(1)", "photo"]
puts filenames(names) # ["photo", "photo(1)", "doc", "photo(1)(1)", "photo(2)"]