Skip to content

Instantly share code, notes, and snippets.

@dested
Created February 18, 2015 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dested/9471dfd2e17a045845f1 to your computer and use it in GitHub Desktop.
Save dested/9471dfd2e17a045845f1 to your computer and use it in GitHub Desktop.
// Write a function 'find' in javascript that takes two argumens:
// N: A 2D Array of numbers where each row and each column are sorted in ascending order.
// v: A number
// If v is present in N, then find should return the position of v in N
// otherwise find should return false.
// Notes:
// Your code should be readable and efficient.
// You may NOT use the Javascript indexOf function in your code.
// For more clarification on the problem, see the example inputs below.
function find(L, v) {
// Write code here.
}
// Example input:
var L = [[1, 2, 3], [14, 15, 16], [27, 28, 29]];
console.log(find(L, 12)); // --> false
console.log(find(L, 30)); // --> false
console.log(find(L, 1)); // --> [0, 0]
console.log(find(L, 29)); // --> [2, 2]
console.log(find(L, 16)); // --> [1, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment