v1
- by nicopowa 4/29/202500
Setup HTML - click to add setup HTML
disable setup JavaScript
Setup JavaScript
const alphabet = "abcdefghijklmnopqrstuvwxyz";
// "l" not repeated
const whatever = "aabbccddeeffgghhiijjkklmmnnooppqqrrssttuuvvwwxxyyzz";

const firstNonRepeated1 = str => {

	if(!str) 
		return null;

	for(let i = 0; i < str.length; i++) 
		if(str.indexOf(str[i]) === str.lastIndexOf(str[i])) 
			return str[i];

	return null;

}

const firstNonRepeated2 = str => {
	
	if(!str) 
		return null;

	const freq = {};
	
	for(const char of str) 
		freq[char] = (freq[char] || 0) + 1;
	
	for(const char of str) {
		if(freq[char] === 1) 
			return char;
	}
	
	return null;

};

const firstNonRepeated3 = str => {
	
	const charCount = new Map();
	
	for(let i = 0; i < str.length; i++) {
		const char = str[i];
		charCount.set(char, (charCount.get(char) || 0) + 1);
	}

	for(let i = 0; i < str.length; i++) {
		const char = str[i];
		if(charCount.get(char) === 1) 
			return char;
	}

	return null;

};
delete caserun single casemove downdrag and drop case


ready



firstNonRepeated2(alphabet);
firstNonRepeated2(whatever);
delete caserun single casemove upmove downdrag and drop case


ready



firstNonRepeated3(alphabet);
firstNonRepeated3(whatever);
delete caserun single casemove updrag and drop case


ready



firstNonRepeated1(alphabet);
firstNonRepeated1(whatever);
Test Case - click to add another test case
Teardown JS - click to add teardown JavaScript
Output (DOM) - click to monitor output (DOM) while test is running
RUN