Created
November 9, 2018 03:23
-
-
Save AminBusiness/de6b219bca84e3f4bf027419797a3bf1 to your computer and use it in GitHub Desktop.
// source https://jsbin.com/gavovuh
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
<script id="jsbin-javascript"> | |
//Challenge 10 Anagram | |
//Returns true if anagram is false or not | |
function isAnagram(str1, str2) | |
{ | |
return formatStr(str1) === formatStr(str2); | |
} | |
function formatStr(str) | |
{ | |
return str | |
//replace anything that is not a word character | |
.replace(/[^\w]/g, ' ') | |
.toLowerCase() | |
.split('') | |
.sort() | |
.join('') | |
} | |
const output = isAnagram('elbow', 'below'); | |
console.log(output); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">//Challenge 10 Anagram | |
//Returns true if anagram is false or not | |
function isAnagram(str1, str2) | |
{ | |
return formatStr(str1) === formatStr(str2); | |
} | |
function formatStr(str) | |
{ | |
return str | |
//replace anything that is not a word character | |
.replace(/[^\w]/g, ' ') | |
.toLowerCase() | |
.split('') | |
.sort() | |
.join('') | |
} | |
const output = isAnagram('elbow', 'below'); | |
console.log(output);</script> |
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
//Challenge 10 Anagram | |
//Returns true if anagram is false or not | |
function isAnagram(str1, str2) | |
{ | |
return formatStr(str1) === formatStr(str2); | |
} | |
function formatStr(str) | |
{ | |
return str | |
//replace anything that is not a word character | |
.replace(/[^\w]/g, ' ') | |
.toLowerCase() | |
.split('') | |
.sort() | |
.join('') | |
} | |
const output = isAnagram('elbow', 'below'); | |
console.log(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment