Solutions in four tests in Codility on JavaScript