?
Solved

FREQUENCY LIST OF NAMES

Posted on 2003-10-22
6
Medium Priority
?
187 Views
Last Modified: 2008-02-01
Dear Experts,

I would need your helpfull to build a script which would create a sorted frequency list
from a list of names, from a <textarea> to another <textarea>

For example:

FROM

<textarea>

Charles Letchev
Edmund Casparot
Ray Davies da Silva
Ronaldo Marcado
Noites e Dias da Silva
Maria Camilla Freindlich
Kenshin Himura
Satoro Sato
Jane Austin
Miguel da Silva
Edmund Casparot
Ronaldo marcado
Jane Austin
Charles Letchev
</textarea>

TO
<TEXTAREA>
Charles Letchev                  2
Edmund Casparot               2
Jane Austin                        2
Kenshin Himura                  1
Maria Camilla Freindlich      1
Miguel da Silva                   1
Noites e Dias da Silva          1
Ray Davies da Silva             1
Ronaldo Marcado                2
Satoro Sato                        1
</TEXTAREA>


Thank you very much.


soperl





</textarea>

0
Comment
Question by:soperl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 25

Expert Comment

by:devic
ID: 9603103
hi soperl,

try this:
=========================================
<html>
<head>
      <title>Untitled</title>
      <META http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>

<body bgcolor=ffffff topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>
<script>
function runit()
{
      var mytext1=document.getElementById("t1");
      var mytext2=document.getElementById("t2");
      var mytextArr=mytext1.innerHTML.split("\n");
      mytextArr.sort();
      
      mytext2.innerHTML=mytextArr.join("\n");
}
</script>
<textarea id=t1 style=height:300px>
Charles Letchev
Edmund Casparot
Ray Davies da Silva
Ronaldo Marcado
Noites e Dias da Silva
Maria Camilla Freindlich
Kenshin Himura
Satoro Sato
Jane Austin
Miguel da Silva
Edmund Casparot
Ronaldo marcado
Jane Austin
Charles Letchev
</textarea>

<textarea id=t2 style=height:300px>
</textarea>

<button onclick=runit()>runit</button>
</body>
</html>
0
 
LVL 6

Expert Comment

by:ren_b
ID: 9603120
so what you want is to just put the number of times each name shows up in textarea 1, in textarea 2?

this is probably a bad way to do it, but it'd work:

you'd make textarea 1 a string...

var text1 = document.forms[0].elements[0]; //assuming its the first eleemnt in the form
var text2 = document.forms[0].elements[1]; //same deal

var text1_names = text1.value.split('\n');

for (var a=0;a<text1_names.length;a++){
  var names[a] = 0;
  for (var b=0;b<text1_names.length;b++){
    if (text1_names[a] == text1_names[b]){
      var name[b]=text1_name[b];
      names[b]++;
}}}
for (var c=0;c<name.length;c++)
  text2.value += names[c] + " " + name[c] + "\n";


i think that should work, though i haven't tested it
0
 

Author Comment

by:soperl
ID: 9605790

Dear devic,

Your function works fine, but I would need the frequencies side by side of names.

----------------------------------


Dear ren_b,

Yes, but deleting the lines in duplicate.

Please complete your function() to be most clear to me.

-----------------------------------

soperl
0
ATEN's HDBaseT Presentation at InfoComm 2017

Hear ATEN Product Manager YT Liang review HDBaseT technology, highlighting ATEN’s latest solutions as they relate to real-world applications during her presentation at the HDBaseT booth at InfoComm 2017.

 
LVL 25

Accepted Solution

by:
devic earned 1040 total points
ID: 9615478

soperl, here is solution:
======================================
<html>
<head>
    <title>Untitled</title>
    <META http-equiv="Content-Type" content="text/html; charset=windows-1251">
</head>

<body bgcolor=ffffff topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>
<script>
function runit()
{
    var mytext1=document.getElementById("t1");
    var mytext2=document.getElementById("t2");
      var tmpspan=document.getElementById("tmpspan");
    var mytextArr=mytext1.innerHTML.replace(/\r/,"").split("\n");
      mytextArr.sort();
      tmpspan.innerHTML=countitems(mytextArr).join("<br>");
      mytext2.innerText=tmpspan.innerText;
}
function countitems(myarr)
{
      var origarr=myarr;
      var resarr=myarr;
      for(var i=0;i<myarr.length;i++)
      {
            var tmp=0;
            for(var j=0;j<origarr.length;j++)
            {
                  if(origarr[j].toLowerCase().indexOf(myarr[i].toLowerCase())!=-1)
                  {
                        tmp++;
                  }
            }
            resarr[i]=origarr[i]+" :"+tmp;
      }
      return removedublicate(myarr);
}
function removedublicate(myarr)
{
      var resarr=new Array();
      var j=0;
      for(var i=0;i<myarr.length;i++)
      {
            if(resarr.toString().toLowerCase().indexOf(myarr[i].toLowerCase())==-1)
            {
                  resarr[j]=myarr[i];
                  j++;
            }
      }
      return resarr;
}
</script>
<textarea id=t1 style=height:300px;width:400px;>
Charles Letchev
Edmund Casparot
Ray Davies da Silva
Ronaldo Marcado
Noites e Dias da Silva
Maria Camilla Freindlich
Kenshin Himura
Satoro Sato
Jane Austin
Miguel da Silva
Edmund Casparot
Ronaldo marcado
Jane Austin
Charles Letchev

</textarea>
<textarea id=t2 style=height:300px;width:400px;></textarea>
<div id=tmpspan style=display:none;></div><br>
<button onclick=runit()>runit</button>
</body>
</html>

======================================
if you want to be "Ronaldo marcado" not equal to "Ronaldo Marcado" (case-sensitive)
then remove .toLowerCase()
0
 
LVL 25

Expert Comment

by:devic
ID: 9626644
hi soperl,

did you solved your problem?
0
 

Author Comment

by:soperl
ID: 9628834
Dear devic,

No doubt! Solve my problem!

Thank you very much.

soperl,
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question