tags:

views:

86

answers:

2

So I want to scan 2 Datum, these are texts, then I will rate it if it has relevancy.

Example:

Data: individual facts
Data: statistics, items of information individual facts

This is my JS code that will scan the whole webpage:

var listitem, thislist;
var itemname = new Array();
listitem = getElementsByClass('Forwards');
for(var i = 0; i < listitem.length; i++) {  
if (listitem[i].innerHTML.match(/Data:/)) itemname.push(listitem[i].innerHTML);
}

So the itemname array contains the texts. The first array contains:

Data: individual facts

The second array contains:

Data: statistics, items of information individual facts

As you can see the second array contains more information:

Data: statistics, items of information

But they are relevant right?

So I want to to return TRUE

How would I code this?

A: 

I'm assuming that your data conforms to "Data: [data Element], [data Element]..." -- after the initial colon individual elements are separated by a comma.

So, what you want to do is extract the data (everything after the colon) and break it down into individuals (everything between commas)

    function ProcessDatum(datum){
    var str = datum.toString();
    var dataPieces = str.substr(str.indexOf(':')).split(',');
    return dataPieces;
}

    function CompareData(first, second){
    // Do your usual array compare stuff, I don't know what would be best for you
    // What you want to do is to check if any element of second appears in first
}

ProcessDatum() will give you an array of the individual data from your original "Data: first, second, third". CompareData() on two datasets to process.

Lansen Q
A: 

Hi guys

Let's make this simpler, I just want to a script that will scan the strings. Then if it find a 2 matches, it will return true.

For example if string 1 = "Blue big doll" then string 2 = "Blue doll". Both of the have "BLUE" & "doll" inside their string, so it will return true. If string 2 = "BLUE" it will return false because the condition is 2 matches.

Raymond G.