Skip to content

Instantly share code, notes, and snippets.

@ayhansipahi
Created February 18, 2016 22:14
Show Gist options
  • Save ayhansipahi/a6822bbd2c8d87e9914d to your computer and use it in GitHub Desktop.
Save ayhansipahi/a6822bbd2c8d87e9914d to your computer and use it in GitHub Desktop.
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