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 shapeArea(n) { | |
return 2*Math.pow(n,2) - 2*n +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 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 allLongestStrings(inputArray) { | |
var result=[""]; | |
var count=0; | |
for(var i=0;i<inputArray.length;i++){ | |
if(inputArray[i].length>=result[result.length-1].length){ | |
if(inputArray[i].length>result[result.length-1].length) | |
count=1; | |
else | |
count++ | |
result.push(inputArray[i]); |
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 commonCharacterCount(s1, s2) { | |
var string1=s1.split(''); | |
var string2=s2.split(''); | |
var common=0; | |
for(var i=0;i<string1.length;i++){ | |
if(string2.indexOf(string1[i])>=0){ | |
common++; | |
string2.splice(string2.indexOf(string1[i]),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 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++){ |
OlderNewer