Skip to content

Instantly share code, notes, and snippets.

@Troush
Created June 14, 2016 13:32
Show Gist options
  • Save Troush/7efbf8fe7efd2016224c705db4b5ff69 to your computer and use it in GitHub Desktop.
Save Troush/7efbf8fe7efd2016224c705db4b5ff69 to your computer and use it in GitHub Desktop.
def compact_units([] = vals, units) do
"#{units}"
end
def compact_units([h |[]] = vals, units) do
"#{h} #{compact_units([], units)}"
end
def compact_units([h|t] = vals, units) do
"#{h} x #{compact_units(t, units)}"
end
@Troush
Copy link
Author

Troush commented Jun 14, 2016

compact_units([obj.length, obj.height, obj.width], "m") // 2.5 x 1.4 x 2 m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment