Created
June 21, 2016 14:44
-
-
Save brainyfarm/e24d3a956db8a80f4ce52a5403e4dada to your computer and use it in GitHub Desktop.
Olawale/FreeCodeCamp Algorithm: Mutation
This file contains hidden or 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
/* | |
Here is my old solution. | |
We get better with time! | |
function mutation(arr) { | |
// Split the first and second string into an array | |
var firstWord = arr[0].toLowerCase().split(""); | |
var secondWord = arr[1].toLowerCase().split(""); | |
// Define a variable keeper to to store number of chars in secondWord present in the first. | |
var keeper = 0; | |
// Loop through the secondWord | |
for(i=0;i<secondWord.length;i++){ | |
// Add one to the value of keeper if the character is present in firstWord | |
if(firstWord.indexOf(secondWord[i]) > -1 ) keeper += 1; | |
} // End of for loop | |
// Check if keeper's length is equal to the length of secondWord and return true or false | |
return keeper === secondWord.length ? true : false; | |
} | |
mutation(["hello", "heey"]); | |
*/ | |
/* New Solution Here */ | |
function mutation(arr) { | |
for(var i =0; i< arr[1].length; i++){ | |
if(arr[0].toLowerCase().indexOf(arr[1][i].toLowerCase()) === -1) | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment