Javascript String isAnagram(comparison)

Description

Javascript String isAnagram(comparison)


String.prototype.isAnagram = function(comparison) {
  var length = comparison.length - 1;
  for(var i = 0; i < this.length; i++) {
    if(this[i] != comparison[length - i]) {
      return 'not anagram';
    }/*from  ww w. j a  v a  2 s . c  o m*/
  }

  return 'its an anagram!';
}

var word = "Department";
var drow = "tnemtrapeD";

console.log(word.isAnagram(drow));



PreviousNext

Related