code snippets to solve some common problems in javascript