- 1 Count the number of Duplicates
Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits.
- 2 Take a Ten Minute Walk
You live in the city of Cartesia where all roads are laid out in a perfect grid. You arrived ten minutes too early to an appointment, so you decided to take the opportunity to go for a short walk. The city provides its citizens with a Walk Generating App on their phones -- everytime you press the button it sends you an array of one-letter strings representing directions to walk (eg. ['n', 's', 'w', 'e']). You always walk only a single block for each letter (direction) and you know it takes you one minute to traverse one city block, so create a function that will return true if the walk the app gives you will take you exactly ten minutes (you don't want to be early or late!) and will, of course, return you to your starting point. Return false otherwise.
- 3 Multiples of 3 or 5
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in.
- 4 Convert string to camel case
Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized only if the original word was capitalized (known as Upper Camel Case, also often referred to as Pascal case).
-
-
Save HenriqueMitsuo/d5fb9f159e70cdd0f666e3864dc20601 to your computer and use it in GitHub Desktop.
JS Stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! MY SOLUTION 😏 | |
function duplicateCount(text) { | |
let count = 0; | |
let result = 0; | |
if (text.length === 0) { | |
return 0; | |
} else { | |
let newText = text.toLowerCase().split("").sort(); | |
console.log(newText); | |
newText.forEach((element, index, array) => { | |
for (let i = index + 1; i < newText.length; i++) { | |
if (element == newText[i]) { | |
count++; | |
} | |
} | |
if (count > 0) { | |
result++; | |
} | |
array = array.splice(0, count); | |
count = 0; | |
}); | |
} | |
return result; | |
} | |
//! Solution 😄 | |
function duplicateCount2(text) { | |
return ( | |
text | |
.toLowerCase() | |
.split("") | |
.sort() | |
.join("") | |
.match(/([^])\1+/g) || [] | |
).length; | |
} | |
console.log(duplicateCount2("AaBbaa22BBcC")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isValidWalk(walk) { | |
let X = 0; | |
let Y = 0; | |
if (walk.length == 10) { | |
walk.forEach((element) => { | |
if (element == "n") X++; | |
if (element == "s") X--; | |
if (element == "w") Y++; | |
if (element == "e") Y--; | |
}); | |
return X == 0 && Y == 0 ? true : false; | |
} else { | |
return false; | |
} | |
} | |
console.log(isValidWalk(['n','s','n','s','n','s','n','s','n','s'])); | |
console.log(isValidWalk(['n','n','n','s','n','s','n','s','n','s'])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solution(number) { | |
let num = []; | |
let i = 1; | |
while (i < number) { | |
num.push(i); | |
i++; | |
} | |
let newArray = num.filter((number) => number % 3 == 0 || number % 5 == 0); | |
return newArray.length > 0 | |
? newArray.reduce((total, number) => total + number) | |
: 0; | |
} | |
console.log(solution(10)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! MY SOLUTION 😏 | |
const toCamelCase = (str) => { | |
let newStr = ""; | |
if (str) { | |
str = str.replace(/[-_]/g, " ").split(" "); | |
str.forEach((word, index, arr) => { | |
if (!index == 0) | |
arr[index] = word.charAt(0).toUpperCase() + word.slice(1); | |
}); | |
newStr = str.join(""); | |
} | |
return newStr; | |
}; | |
//! Solution 😄 | |
const toCamelCase2 = (str) => str.replace(/[-_](.)/g, (_, c) => c.toUpperCase()); | |
console.log(toCamelCase("the_stealth_warrior")); | |
console.log(toCamelCase2("the_stealth_warrior")); | |
console.log(toCamelCase("The-Stealth-Warrior")); | |
console.log(toCamelCase2("The-Stealth-Warrior")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment