Algorithm (JS) Basic