JS劝退

题目:

计算一个字符串中有重复字符的个数:

例:

var str = '112233'   // 3

var str1 ='aabbccdd'  //4

let demo = (str)=>{
			let array = str.toString().split('');
			let obj = {};
			let number = 0;
			array.map((item)=>{
				obj[item]?(obj[item]++):obj[item]=1;
				(obj[item]==2)&&(number++);
			})
			return number;
		}
		console.log(demo(112233445566));

 

你可能感兴趣的:(javascript学习笔记)