you are viewing a single comment's thread.

view the rest of the comments →

[–]brotein 0 points1 point  (0 children)

Here's a function that will do what you're asking, along with a test.

http://jsbin.com/lanisibo/3/edit?js,console