Is String Anagram - Node.js String

Node.js examples for String:Algorithm

Description

Is String Anagram

Demo Code


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  w w  w  . j a  v  a2  s .co  m
  }

  return 'its an anagram!';
}

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

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

Related Tutorials