Algorith Basics in JavaScript