diff --git a/isUnique/isUnique.js b/isUnique/isUnique.js index 6c9caf5..7489ab2 100644 --- a/isUnique/isUnique.js +++ b/isUnique/isUnique.js @@ -1,3 +1,14 @@ /* Implement an algorithm to determine if a string has all unique characters. * What if you cannot use additional data structures? - */ \ No newline at end of file + */ + + const isUnique = (str) => { + let currentChar = str.charAt(0); + for(let i = 1; i < str.length; i++) { + let newChar = str.charAt(i); + if(currentChar === newChar) { + return false; + } + } + return true; +}; diff --git a/longestString/longestString.js b/longestString/longestString.js index 35b887c..33040a5 100644 --- a/longestString/longestString.js +++ b/longestString/longestString.js @@ -2,3 +2,13 @@ * Write a function that accepts an array of strings. * Return the longest string in the array. */ + +const longestString = (stringArray) => { + let currentLongest = stringArray[0]; + for(strings of stringArray) { + if(strings.length > currentLongest.length) { + currentLongest = strings; + } + } + return currentLongest; +} \ No newline at end of file diff --git a/reverseCase/reverseCase.js b/reverseCase/reverseCase.js index f1051f5..74a7f0a 100644 --- a/reverseCase/reverseCase.js +++ b/reverseCase/reverseCase.js @@ -2,4 +2,19 @@ * Write a function that reverses the case of each letter in the strings that it receives. * Example: 'Hello World' -> 'hELLO wORLD' * Assume that each string will contain only spaces and letters. - */ \ No newline at end of file + */ + + const reverseCase = (str) => { + let newString = ''; + for (let i = 0; i < str.length; i++) { + let character = str.charCodeAt(i); + if ((character >= 65) && (character <= 90)) { + newString = newString + (str.charAt(i).toLowerCase()); + } else if ((str.charCodeAt(i) >= 97) && (str.charCodeAt(i) <= 122)) { + newString = newString + (str.charAt(i).toUpperCase()); + } else { + newString = newString + ' '; + } + } + return newString; +}