-
Notifications
You must be signed in to change notification settings - Fork 340
Bonfire Mutations
Created by Rafase282
Github | FreeCodeCamp | CodePen | LinkedIn | Website | E-Mail
- Difficulty: 1/5
Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.
For example, ['hello', 'Hello'], should return true because all of the letters in the second string are present in the first, ignoring case.
The arguments ['hello', 'hey'] should return false because the string 'hello' does not contain a 'y'.
Lastly, ['Alien', 'line'], should return true because all of the letters in 'line' are present in 'Alien'.
Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.
function mutation(arr) {
return arr;
}
mutation(['hello', 'hey']);
You basically have to check if the string in the first parameter contains all the characters found on the second parameter.
First make the arguments lowercase and arrays so we can compare without having to worry about the case.
Use indexOf()
to check if the letter of the second word is on the first.
You will need a way to check if all the words are in the first one, like keeping a counter and checking for a default value.
function mutation(arr) {
var first = arr[0].toLowerCase().split('');
var second = arr[1].toLowerCase().split('');
var temp = 0;
// Check every character and if the index is found add one
for (var s in second){
if (first.indexOf(second[s]) > -1) {
temp+= 0;
} else
temp+=1;
}
if (temp === 0)
return true;
else
return false;
}
- take the first and second parameter and make them lowercase and split them by characters.
- Create a temp variable to keep count.
- For each letter in the second parameter, check if it is found on the first, if so then add 0 to the tamp variable, otherwise add 1.
- Outside the loop, if temp is 0 then return true, otherwise false, this acts as an on and off. If all the letters were added then we just get 0, otherwise there will be at least a
1
which means one letter was not found.
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