// find elements
var banner = $("#banner-message")
var button = $("button")
function checkem(string1,string2) {
var result = false;
// pseudo
// walk throug each letter of first string
// if found anywhere in second string remove it from both
// at end if 1st and 2nd string are empty, they are anagrams
// ignore spaces and special characters
// convert to lower
// get rid of bad characters
// if lengths at start aren't same it fails
//
for (var i=0;i<string1.length;i++){
string2=string2.replace(string1[i],"");
}
console.log(string1,string2);
return string2 == "";
}
// handle click and add class
button.on("click", () => {
console.log(checkem("get","etg")); // sould be true
console.log(checkem("aget","atgo")); // sould be false
/* Check to see if the two provided strings are anagrams of each other.
One string is an anagram of another if it uses the same characters
in the same quantity. Only consider characters, not spaces
or punctuation. Consider capital letters to be the same as lower case
--- Examples
anagrams('rail safety', 'fairy tales') --> True
anagrams('RAIL! SAFETY!', 'fairy tales') --> True
anagrams('Hi there', 'Bye there') --> False */
})
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.