Skip to content

Instantly share code, notes, and snippets.

@outoftime
Last active December 25, 2015 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save outoftime/6963585 to your computer and use it in GitHub Desktop.
Save outoftime/6963585 to your computer and use it in GitHub Desktop.
Make me a sorted set.
var SortedSet = function () {
// your code here...
}
var set = new SortedSet()
set.add(3).add(1).add(3).add(5).add(8).add(-4).add(6)
var answer = [-4, 1, 3, 5, 6, 8]
if (set.toArray() < answer || set.toArray() > answer) {
console.log("Got ", set.toArray())
process.exit(1)
}
import sys
class SortedSet:
# your code here...
set = SortedSet()
set.add(3).add(1).add(3).add(4).add(8).add(-4).add(6)
if list(set) != [-4, 1, 3, 5, 6, 8]:
print("Got ", list(set))
sys.exit(1)
class SortedSet
# your code here...
end
set = SortedSet.new
set << 3 << 1 << 3 << 5 << 8 << -4 << 6
abort "Got #{set.to_a.inspect}" unless set.to_a == [-4, 1, 3, 5, 6, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment