sahil sahil - 1 year ago 65
Javascript Question

Return an Boolean array by matching words in two arrays

The function

should return which of the keywords are present in the text in the form of boolean array like:
array: [true, false, false]
. based on the second argument to the function. Right now, I am able to return only the
values, I do not know how to return
values when the case is false. The code is below. The output should be [true, false, false]

{function keywordusage(str,strArr){
var count = [];
var found = true;
var notfound = false;
var words = str.split(' ');
var wordsLength = words.length;
var ArrLength = strArr.length;
for(var i = 0; i < ArrLength; i++){
for(var j = 0; j < wordsLength; j++){
return count;

document.write(keywordusage('Dive Into Python is a free book for experienced programmers', ['Python', 'python', 'scala']));}

Answer Source
function keywordusage(text, keywords) {
    var elements = text.split(" ");
    var result = Array();
    for (var i=0; i < keywords.length;i++){
        if (elements.indexOf(keywords[i]) >= 0)
            result[i] = true;
            result[i] = false;
    }//end of for loop
    return result;

var result = keywordusage('Dive Into Python is a free book for experienced programmers', ['Python', 'python', 'scala']);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download