JSFiddle - React, Tailwind, and code Playground

by meetravi

JavaScript

function solution(str, arr) {
  let val = 0;
  for (let i = 0; i < str.length - 1; i++)
    // If two consecutive characters are
    // the same, delete one of them.
    let deletionValue; 
    if (str[i] === str[i + 1]) {
      console.log("solution -> i", i);
      console.log("solution -> str[i]", str[i]);
      console.log("solution -> arr[i]", arr[i]);
      val++;
    }
  console.log("solution -> val", val);
  return val;
}

solution("abccbd", [0, 1, 2, 3, 4, 5]); // Should return 2

solution("aabbcc", [1, 2, 1, 2, 1, 2]); // Should return 3