Created
February 18, 2016 22:14
-
-
Save ayhansipahi/a6822bbd2c8d87e9914d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function solution(X, A) { | |
// write your code in JavaScript (Node.js 4.0.0) | |
var l = A.length; | |
for(var n = 1; n<l-1;n++){ | |
sol = A.slice(n), | |
sag = A.slice(0,n); | |
var x = sol.reduce(function(a,b){if(b==X){a++} return a},0); | |
var y = sol.reduce(function(a,b){if(b!=X){a++}return a},0); | |
if(x==y){return n-1}; | |
} | |
return null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment