function mostFrequentWord(words: string[]) {
let frequency: number = 0;
const size: number = words.length;
let frequent_word: string = "";
for (let i: number = 0; i < size; i++) {
let count: number = 1;
for (let j: number = i + 1; j < size; j++) {
if (words[j]== words[i]) {
count++;
}
}
if (count >= frequency) {
frequent_word = words[i];
frequency = count;
}
}
return frequent_word;
}
const arr: string[] = ["java", "c++", "c", "c#", "c", "go", "php", "java", "java", "c", "typescript", "php", "c"];
const frequent_word = mostFrequentWord(arr);
console.log(frequent_word);
/*
run:
"c"
*/