Home > Web Front-end > JS Tutorial > body text

Find the most frequent letters and occurrences in a string - javascript tips

WBOY
Release: 2016-05-16 17:48:40
Original
1600 people have browsed it

Copy code The code is as follows:



isNaN(x) If x is the special non-numeric value NaN (or can be converted to such a value), The returned value is true. If x is any other value, returns false.
i is index
If the first loop
a[i] is 't'
b[a[i]] is b['t'] and the access subscript is 't' The object
b[a[i]] that is not a number is always NaN
isNaN(b[a[i]] ) is true because b has no subscript and the object b with t is now empty
! isNaN(b[a[i]] ) is false
!isNaN(b[a[i]] )||(b[a[i]]=1); or operator||If one is true, it is true The expression on the left is false, so then executing the expression on the right can be regarded as the abbreviation of the conditional statement if(isNaN(b[a[i]] )){b[a[i]]=1}
(b[a [i]]=1); If the left one is not true, set the subscript of b b['t']=1;
Loop again and if t is encountered, t will be executed successfully. If not, continue to set the subscript
This example does not take into account spaces, special characters, etc.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template