Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(string) {
- let updatedStr = string[0];
- let currentChar = string[0];
- for (let i = 1; i < string.length; i++) {
- if (string[i] !== currentChar) {
- updatedStr += string[i];
- currentChar = string[i];
- }
- }
- console.log(updatedStr);
- }
- /*function solve(string) {
- let output = string[0];
- for (let i = 1; i < string.length; i++) {
- let current = string[i];
- let previous = string[i - 1];
- if (current !== previous) {
- output += current;
- }
- }
- console.log(output);
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement