programming-examples/js/Functions/Write a JavaScript function to find the first not repeated character..js

23 lines
489 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
function find_FirstNotRepeatedChar(str) {
var arra1 = str.split('');
var result = '';
var ctr = 0;
for (var x = 0; x < arra1.length; x++) {
ctr = 0;
for (var y = 0; y < arra1.length; y++)
{
if (arra1[x] === arra1[y]) {
ctr+= 1;
}
}
if (ctr < 2) {
result = arra1[x];
break;
}
}
return result;
}
console.log(find_FirstNotRepeatedChar('abacddbec'));