Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def catalogUpdate(catalog, updates)
- updates_length = updates.length
- catalog_length = catalog.length
- x = 0
- y = 0
- found = false
- while (x < updates_length)
- while (y < catalog_length)
- if updates[x][0] == catalog[y][0] then
- catalog[y].push(updates[x][1])
- found = true
- value = catalog[y][0]
- catalog[y] = catalog[y] - [value]
- catalog[y] = catalog[y].sort
- catalog[y] = catalog[y].unshift(value)
- end
- y = y + 1
- end
- if found == false then
- catalog.push(updates[x])
- catalog_length = catalog.length
- end
- y = 0
- x = x + 1
- found = false
- end
- catalog = catalog.sort {|a, b| a[0] <=> b[0]}
- return catalog
- end
Advertisement
Add Comment
Please, Sign In to add comment