-
Notifications
You must be signed in to change notification settings - Fork 340
Bonfire Missing letters
Rafael J. Rodriguez edited this page Jan 6, 2017
·
2 revisions
Created by Rafase282
Github | FreeCodeCamp | CodePen | LinkedIn | Website | E-Mail
- Difficulty: 2/5
Find the missing letter in the passed letter range and return it.
If all letters are present in the range, return undefined.
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
function fearNotLetter(str) {
return str;
}
fearNotLetter('abce');
- You will create a program that will find the missing letter from a string and add it. If there is not missing letter it will return undefined. There is currently no test case for it missing more than one letter, but if anything recursion can be implemented or a second or more calls to the same function as needed. Also the letters are always provided in order so there is no need to sort them.
- You will need to convert from character to ASCII code using the two methods provided in the description.
- You will have to check for the difference in ASCII code as they are in order. Using a chart would be very helpful.
- You will need to figure out where to insert the letter and how to do it, along with handling the case that there is not missing letter as it needs an specific return value.
Solution ahead!
function fearNotLetter(str) {
// Create our variables.
var firstCharacter = str.charCodeAt(0);
var valueToReturn = '';
var secondCharacter = '';
// Function to find the missing letters
var addCharacters = function(a, b) {
while (a - 1 > b) {
b++;
valueToReturn += String.fromCharCode(b);
}
return valueToReturn;
};
// Check if letters are missing in between.
for (var index = 1; index < str.length; index++) {
secondCharacter = str.charCodeAt(index);
// Check if the diference in code is greater than one.
if (secondCharacter - firstCharacter > 1) {
// Call function to missing letters
addCharacters(secondCharacter, firstCharacter);
}
// Switch positions
firstCharacter = str.charCodeAt(index);
}
// Check whether to return undefined or the missing letters.
if (valueToReturn === '')
return undefined;
else
return valueToReturn;
}
- Read comments in code.
Thanks for visiting, if you like this please feel free to star my repo, follow me or even contact me about contributing as it will be a lot of work and having help would be cool.
- HTML5 and CSS
- Responsive Design with Bootstrap
- Gear up for Success
- jQuery
- Basic JavaScript
- Object Oriented and Functional Programming
- Basic Algorithm Scripting
- Basic Front End Development Projects
- Intermediate Algorithm Scripting
- JSON APIs and Ajax
- Intermediate Front End Development Projects
- Claim Your Front End Development Certificate
- Upper Intermediate Algorithm Scripting
- Automated Testing and Debugging
- Advanced Algorithm Scripting
- AngularJS (Legacy Material)
- Git
- Node.js and Express.js
- MongoDB
- API Projects
- Dynamic Web Applications
- Claim Your Back End Development Certificate
- Greefield Nonprofit Project 1
- Greefield Nonprofit Project 2
- Legacy Nonprofit Project 1
- Legacy Nonprofit Project 2
- Claim your Full Stack Development Certification
- Whiteboard Coding Interview Training
- Critical Thinking Interview Training
- Mock Interview 1
- Mock Interview 2
- Mock Interview 3