The detection method of JavaScript palindrome and class name

Source: Internet
Author: User

palindrome * *
"123" changed to "123321"
"abc321" changed to "ABCD321123CBA"
function fn (str) {
Convert string to string array (with or without spaces)
  var arr=str.split (');
  Console.log (arr);
Reverses the order of string arrays
  var reversearr=arr.reverse ();
  Console.log (Reversearr);
Stitching arrays of inverted order into strings (with or without spaces)
  var reversestr=reversearr.join ("");
  Console.log (REVERSESTR);
Stitch the original string together with the inverted string to get the result
  return str+reversestr;
  //Shorthand
  //returen Str+str.split (""). Reverse.join ("");
}
Console.log (FN ("This was an apple");
Console.log (FN ("abc321"));
Detecting class names
function  Checkclass (A, b) {
  //Get class an array group
  var allclass = A.split (");
  Console.log (Allclass);
Determines whether the value of B has occurred in the array
If it does not appear (with: true, no: false)
  var i=0;
  var result=false;
For  (; i<allclass.length;i++) {
  if (allclass[i]===b) {
If these two values are equal, the value of an item in the array is equal to B, and the previous assumption is wrong.
  result=true;
Break  ;
  }
  }
  return result;
}
The IndexOf method, if not found, returns-1, if found, returns the angle label of the array
  if (allclass.indexof (b) = = = 1) {
  return false;
  } else {
  return true;
  }
}
Console.log (Checkclass ("Name right", "right"));
Console.log (Checkclass ("Name right", "left");
var obj1 = {
A:10,
B:20
};
?
var obj2 = obj1;
?
obj1.a = 30;
?
Console.log (obj2.a);
Console.log (obj1.a);
?
Reference type: When assigning data of a reference type to a variable, it does not assign the data itself to the variable, but instead assigns the reference to the variable
?
var arr = [1, 2, 3];
var arr2 = arr;
ARR[1] = 10;
Console.log (ARR2);

The detection method of JavaScript palindrome and class name

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.