I have this event ...
<textarea id="chat"> </textarea>
<button type="button" onclick="play_song();">talk</button>
... causing the following function:
var input = function() {
var chat = document.getElementById("chat").value.split(" ");
return chat && console.log(chat);
}
then there function:
function setIntersection(a, b) {
var result = [];
for (var i = 0; i < a.length; i++) {
if (b.indexOf(a[i]) !== -1 && result.indexOf(a[i]) === -1) {
result.push(a[i]);
}
}
return result;
}
a prototype function:
Song.prototype.lyricsIntersect = function(input) {
var bestSong = null;
var bestCount = -Infinity;
for (var i in songs) {
var currentCount = setIntersection(songs[i].lyrics, input).length;
if (currentCount > bestCount) {
bestSong = songs[i];
bestCount = currentCount;
}
}
return bestSong && bestSong.name;
}
The code ends here:
function play_song() {
var id = Song.prototype.lyricsIntersect(input);
var element = document.getElementById(id);
element.play();
}
but console.logreturns:Uncaught TypeError: b.indexOf is not a function
If I test var input = ["one", "two"];, however, I get the intersection done on the code, depending on input.
What am I missing?
source
share