Jump to content

removing text


freddyw

Recommended Posts

So basically im trying to create a function that checks lines entered into a text box that removes duplicates completely.

 

For example in the text box this is wrote.

 

The

And

To

What

Where

The

One

And

Where

 

I dont want duplicates changing to one. I want them out. So it reads

 

 

To

What

One

 

Just a starting point would help please.

 

 

Link to comment
Share on other sites

Well, here's a function that takes an array of words and returns non-duplicates to your specifications.

 

function noDupes (arr) {
     var tmp = new Array(), results = new Array();
     for (var m = arr.length - 1; m > -1; m--) {
          if (tmp[arr[m]] === undefined) tmp[arr[m]] = 1;
          else tmp[arr[m]] = undefined;
     }
     
     for (var t in tmp) {
          if (t !== undefined) results.push(t);
     }
     return results;
}

var e = noDupes(new Array("the", "and", "to", "where", "and", "the"));

 

Your job is to create the array. I won't help with that. Seems trivial enough.

Link to comment
Share on other sites

Im coming a bit stuck

 

I now have this...

<html>
<head>
    <title>Reomove Dupes</title></head>
        <body>
           
<form onsubmit="removeDups(); return false;">
<textarea rows="30" cols="100" id="list"> </textarea>
<br>
<input type="submit" value="Submit" />
</form>
<script type="text/javascript">
function noDupes (arr) {
     var tmp = new Array(), results = new Array();
     for (var m = arr.length - 1; m > -1; m--) {
          if (tmp[arr[m]] === undefined) tmp[arr[m]] = 1;
          else tmp[arr[m]] = undefined;
     }
     
     for (var t in tmp) {
          if (t !== undefined) results.push(t);
     }
     return results;
}
function removeDups() {
var txtbox = document.getElementById("list");
txtbox.value = noDupes(txtbox.value.split(/\n/)).join("\n");
}
</script>
</body>
</html>

 

if i type

 

the

and

and

 

 

im left with (after clicking submit twice)

 

the

and

 

I want to completely remove what was duplicated meaning the only word left in the box would be 'the'

 

Any ideas?

 

please?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.