Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion isUnique/isUnique.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/* Implement an algorithm to determine if a string has all unique characters.
* What if you cannot use additional data structures?
*/
*/

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;
};
10 changes: 10 additions & 0 deletions longestString/longestString.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
17 changes: 16 additions & 1 deletion reverseCase/reverseCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
*/

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;
}