Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Thing
- def initialize(id)
- @id = id
- end
- def getId
- return @id
- end
- end
- def arrayContainsId(array, id)
- array.each do |thing|
- return true if thing.getId == id
- end
- return false
- end
- things = []
- 10.times do |count|
- things[count] = Thing.new(count + 1)
- end
- newOrder = [69, 2, 3, 5, 25, 4, 8, 9, 6, 420]
- # remove every Thing in things[] that is not in the new newOrder
- things.delete_if{ |thing| !newOrder.include? thing.getId }
- # add new things
- newOrder.each do |id|
- things.push Thing.new(id) if !arrayContainsId(things, id)
- end
- # reorder
- things.sort_by!{|x| newOrder.index x.getId}
- things.each do |things|
- puts things.getId
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement