Ruby versions of JS solutions