Wrote solution in js