All of the other answers so far are using third-party js libraries. The following is an attempt at a straight js solution. Fiddle: http://jsfiddle.net/rNfph/
var M = [
{text:'one', coord: [0,0]},
{text:'two', coord: [1,1]},
{text:'three', coord: [2,2]},
{text:'four', coord: [3,3]},
{text:'five', coord: [4,4]},
{text:'six', coord: [5,5]},
{text:'seven', coord: [6,6]},
{text:'eight', coord: [7,7]},
{text:'nine', coord: [8,8]},
{text:'ten', coord: [9,9]}
];
var search = function(str, x, y){
for(var i=0, len=M.length; i<len; i++){
if( M[i].text === str && M[i].coord[0] === x && M[i].coord[1] === y ){
return true;
}
}
return false;
}
console.log( search('three', 2, 2) );
console.log( search('three', 1, 2) );
Now, take this with a grain of salt. I am not an expert in complexity. There very well could be better ways to do this since this implementation requires iteration through potentially all of the values.
If there was a restriction on this where the value of 'text' is required to be unique, then instead of using an array, you could structure it all as an object (dictionary) and do the checks without needing any iterations at all.
See this fiddle: http://jsfiddle.net/4mrsh/
var M = {
'one': [0,0],
'two': [1,1],
'three': [2,2],
'four': [3,3]
}
var search = function(key, x, y){
if( !M[key] || !(M[key][0] === x && M[key][1] === y) ) return false;
return true;
}
console.log( search('three',2,2) ); //true
console.log( search('three',1,2) ); //false
</p>