Home >Web Front-end >JS Tutorial >A small example of javascript finding the most frequent characters and times in a string_javascript skills

A small example of javascript finding the most frequent characters and times in a string_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:18:331473browse

Copy code The code is as follows:

Untitled Document

<script> </p> <p> var str = 'hskflassssssssskssssdssssussssghgfhssssdsssfh'; </p> <p> var arr = str.split(''); </p> <p> arr.sort(); </p> <p> str = arr.join(''); </p> <p> var re = /(w)1 /g; </p> <p> var value = ''; </p> <p> var num = 0; </p> <p> str.replace(re,function($0,$1){ </p> <p> if($0.length > num){ </p> <p> num = $0.length; </p> <p> value = $1; </p> <p> } </p> <p> }); </p> <p> alert('Most characters: ' value ', number: ' num); </p> <p> </script>


Statement:
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