-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12-7.js
More file actions
28 lines (21 loc) · 727 Bytes
/
12-7.js
File metadata and controls
28 lines (21 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function nestedWordCount (wordList) {
//sort wordList
var sortedList = wordList.sort(function (a,b){return b.length-a.length}) //by length to smallest
console.log(sortedList)
//array of hashes
var myNodes = []
//loop through sortedList and try to add into list
for (i=0; i< sortedList.length ; i++){
var added = false;
for(var j = 0; j < myNodes.length; j++) {
if (myNodes[j].word.toLowerCase().indexOf(sortedList[i].toLowerCase()) != -1) {
myNodes[j].count += 1
added = true;
}
}
if (added === false) myNodes.push({word: sortedList[i], count: 1})
}
var sortans = myNodes.sort(function (a,b){return b.count-a.count})
var value = sortans[0].word
return value
}