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
function adjacentElementsProduct(inputArray) { | |
var i=0,x=inputArray[i]*inputArray[i+1]; | |
i++; | |
while(i+1<inputArray.length){ | |
if(inputArray[i]*inputArray[i+1]>x) | |
x=inputArray[i]*inputArray[i+1]; | |
i++; | |
} | |
return x; | |
} |
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
function makeArrayConsecutive2(statues) { | |
statues=statues.sort((a,b)=>a-b); | |
return(statues[statues.length-1]-statues[0]+1-statues.length); | |
} |
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
function isSmooth(arr) { | |
return (arr.length%2==0) ? arr[0]===arr[arr.length-1]&&arr[0]===(arr[arr.length/2-1]+arr[arr.length/2]):arr[0]==arr[arr.length-1]&&arr[0]==(arr[Math.floor(arr.length/2)]); | |
} |
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
function almostIncreasingSequence(sequence){ | |
var errors=0; | |
for(var i=0;i+1<sequence.length&&errors<2;i++) | |
if(sequence[i]>=sequence[i+1]){ | |
errors++; | |
if(i+2<sequence.length&&i>0) | |
if(sequence[i]>=sequence[i+2]) | |
errors++; | |
} | |
return errors<=1; |
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
function matrixElementsSum(matrix) { | |
price=0; | |
for(var y=0;y<matrix.length;y++) | |
for(var x=0;x<matrix[0].length;x++){ | |
if(y==0) | |
price+=matrix[y][x]; | |
else{ | |
if(matrix[y-1][x]==0) | |
matrix[y][x]=0; | |
price+=matrix[y][x]; |
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
function isLucky(n) { | |
var numbers=n.toString().split(""); | |
var a=0,b=0; | |
for(i=0;i<numbers.length/2;i++){ | |
a+=parseInt(numbers[i],10); | |
b+=parseInt(numbers[numbers.length/2+i],10); | |
} | |
return a===b; | |
} |
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
function sortByHeight(a) { | |
var b=a.slice(0); | |
var x=0; | |
for (var i=0;i<b.length;i++){ | |
if(b[i]<0){ | |
b.splice(i,1); | |
} | |
} | |
b.sort((a,b)=>a-b); | |
for (var j=0;j<a.length;j++){ |
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
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 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 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(""); | |
} |
OlderNewer