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 minesweeper(matrix) { | |
var sum=0; | |
var mines=[],line=[]; | |
for (var y=0;y<matrix.length;y++){ | |
line=[]; | |
for (var x=0;x<matrix[0].length;x++){ | |
sum=0; | |
if(y-1>=0){ | |
if(matrix[y-1][x]) | |
sum++; |
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 boxBlur(image) { | |
var sum=0; | |
var blurred=[],line=[]; | |
for (var x=0;x+3<=image.length;x++){ | |
for (var y=0;y+3<=image[0].length;y++){ | |
sum=0; | |
for (var i=x;i<3+x;i++){ | |
for (var j=y;j<3+y;j++){ | |
sum+=image[i][j]; | |
} |
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 avoidObstacles(inputArray) { | |
var min=2; | |
var test=false; | |
var max=inputArray.reduce(function(a, b) { | |
return Math.max(a, b); | |
}); | |
while(min<=max+1&&!test){ | |
test=true; | |
for(var i=0;i<inputArray.length&&test;i++){ | |
console.log(inputArray[i]+" "+min); |
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 isIPv4Address(inputString) { | |
return /^([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$/.test(inputString); | |
} |
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 arrayMaximalAdjacentDifference(inputArray) { | |
return inputArray.reduce(function(acc,currval,currind,arr){ | |
if(Math.max(currval,arr[currind+1])-Math.min(currval,arr[currind+1])>acc) | |
acc=Math.max(currval,arr[currind+1])-Math.min(currval,arr[currind+1]); | |
return acc; | |
},0); | |
} |
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 areEquallyStrong(yourLeft, yourRight, friendsLeft, friendsRight) { | |
return (((yourLeft==friendsLeft)||(yourLeft==friendsRight))&&((yourRight==friendsLeft)||(yourRight==friendsRight))); | |
} |
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 palindromeRearranging(inputString) { | |
var palindrome=true; | |
var center=0; | |
var array=inputString.split(""); | |
while(palindrome&&array.length>0){ | |
if(array.indexOf(array[0],1)>0) | |
array.splice(array.indexOf(array[0],1),1); | |
else | |
if(center<1) | |
center++; |
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 arrayChange(inputArray) { | |
var moves=0; | |
for(var i=0;i+1<inputArray.length;i++){ | |
if(inputArray[i]-inputArray[i+1]>=0) | |
if(inputArray[i]-inputArray[i+1]==0){ | |
moves++; | |
inputArray[i+1]++; | |
}else{ | |
moves+=inputArray[i]-inputArray[i+1]+1; | |
inputArray[i+1]+=inputArray[i]-inputArray[i+1]+1; |
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 areSimilar(A, B) { | |
var different=[]; | |
for (var i=0;i<A.length;i++){ | |
if (A[i]!=B[i]){ | |
different.push(i); | |
} | |
} | |
if(different.length==0) | |
return true; | |
else |
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 returnLine(text){ | |
var line=["*"]; | |
var letters=text.split(""); | |
for(var i=0;i<letters.length;i++){ | |
line.push(letters[i]); | |
} | |
line.push("*"); | |
return line.join(""); | |
} |