Last active
August 29, 2015 14:01
-
-
Save jimmed/075adc9fd9fb5514fc7d to your computer and use it in GitHub Desktop.
Array::indexOfArr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.indexOfArr = function(search) { | |
var found = -1; | |
this.some(function(v, x) { | |
if(search.length > this.length - x) { | |
return true; | |
} | |
found = x; | |
this.some.call(search, function(sv, y) { | |
if(sv !== this[x+y]) { | |
found = -1; | |
return true; | |
} | |
}, this); | |
return found !== -1 | |
}, this); | |
return found | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array::indexOfArr = (search) -> | |
found = -1 | |
@some (v, x) ~> | |
return true if search.length > this.length - x | |
found := x | |
@some.call search, (sv, y) ~> | |
if sv isnt @[x+y] | |
found := -1 | |
yes | |
found isnt -1 | |
found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1,2,3,4,5,6,7,8,9,10].indexOfArr([3,4,5,6]) // => 2 | |
[1,2,3,4,5,6,7,8,9,10].indexOfArr([3,4,6]) // => -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment