JSFiddle - React, Tailwind, and code Playground

by Arun Tummala

JavaScript

//Find duplicates in string
var string = "arunarunbcc";
var repeateObj = {};
var stringArray = string.split('');
//DO you need another object ? More space complexity
var repeatObjectMorethanOne = [];
for (var i = 0; i < stringArray.length; i++) {
  if (!repeateObj[stringArray[i]]) {
    repeateObj[stringArray[i]] = 1
    console.log(repeateObj)
  } else {
    repeateObj[stringArray[i]] += repeateObj[stringArray[i]]
    repeatObjectMorethanOne[stringArray[i]] = repeateObj[stringArray[i]]
    console.log(repeateObj)
  }
}
console.log(repeatObjectMorethanOne)