Compare Strings in CSP with JavaScript

I have a student who is working through their hackathon project and they want to compare two strings and count how many times that string appears then manipulate that data. I have been trying to find examples for this but all I can think of is Java examples. Does anybody have some examples using the CSP curriculum and JavaScript?

Here is some code that checks for words and removes duplicates

var words = ["one" , "two", "one", "three", "two"];
console.log(words);
var uniqueWords = [];
unique();
console.log(uniqueWords);

function unique(){
  for (var i = 0; i < words.length; i++){
      var count = 0;
      for (var j = i+1; j < words.length; j++){
        if (words[i] == words[j])
          count++;
      }
      if (count == 0){
        appendItem(uniqueWords, words[i]);
      }
  }
}

I hope this helps