DEV Community

Discussion on: Square a number: awful answers only

Collapse
 
codeandclay profile image
Oliver • Edited

Create an x * x array of dots. Count the dots.

def square(value)
  (0...value.abs).flat_map do
    Array.new(value.abs) { "." }    
  end.count(".")    
end
Enter fullscreen mode Exit fullscreen mode