Convert A String To A New String Flashcards
1
Q
First Step
A
create a variable that holds the string value and ignores case:
let word = str.toLowerCase();
2
Q
Second Step
A
Create a variable to hold the finished string to return after it’s looped through
let unique = ‘’;
3
Q
Third Step
A
Loop through all letters in the string:
for (let i = 0; i < words.length; i++) {
}
4
Q
Fourth Step (Inside the loop)
A
//check for letters that repeat:
if (word.lastIndexOf(word[i]) === word.indexOf(word[i]) {
//for each character that never duplicates, place ‘(‘
unique += ‘(‘;
} else {
//for each that is a duplicate, place ‘)’
unique += ‘)’
5
Q
Final Step
A
return unique;