JS solution (work in progress)