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 flip(flipped){ | |
if(flipped.indexOf('(')>=0){ | |
var j=0; | |
var a=0; | |
var b=0; | |
var reversed=[]; | |
while (j<flipped.length&&b==0) { | |
if(flipped[j]=='('){ | |
a=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 alternatingSums(a) { | |
var sum = a.reduce(function(acc, val,currentIndex) { | |
if(currentIndex%2==0) | |
acc[0] += val; | |
else | |
acc[1] += val; | |
return acc; | |
}, [0,0]); | |
return 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 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(""); | |
} |
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 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 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 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 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 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 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); |