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
https://forums.phpfreaks.com/topic/200375-removing-text/
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
https://forums.phpfreaks.com/topic/200375-removing-text/#findComment-1052097
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
https://forums.phpfreaks.com/topic/200375-removing-text/#findComment-1054714
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.