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 extractEachKth(inputArray, k) { | |
| return inputArray.filter((curr,index)=>{ | |
| if((index+1)%k!=0) | |
| return curr; | |
| }); | |
| } |
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 isNext(string1,string2){ | |
| var diff=0; | |
| for(var i=0;i<string1.length;i++){ | |
| if(string1[i]!=string2[i]) | |
| diff++; | |
| } | |
| if (diff!=1) | |
| return false; | |
| else | |
| return true; |
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 absoluteValuesSumMinimization(a) { | |
| var x=a[0],temp=a.reduce((acc,curr)=>{ | |
| return acc+Math.abs(curr-x); | |
| },0); | |
| for(var i=1;i<a.length;i++){ | |
| if(a.reduce((acc,curr)=>{return acc+Math.abs(curr-a[i]);},0)<temp){ | |
| temp=a.reduce((acc,curr)=>{return acc+Math.abs(curr-a[i]);},0); | |
| x=a[i]; | |
| } | |
| } |
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 depositProfit(deposit, rate, threshold) { | |
| var years=0; | |
| while(deposit<threshold){ | |
| deposit+=deposit*(rate/100); | |
| years++; | |
| } | |
| return years; | |
| } |
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 circleOfNumbers(n, firstNumber) { | |
| return (firstNumber*2==n)?0:(firstNumber<(n/2))?firstNumber+(n/2):firstNumber-(n/2); | |
| } |
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 chessBoardCellColor(cell1, cell2) { | |
| if((cell1.charCodeAt(0)-64)%2==0&&(cell2.charCodeAt(0)-64)%2==0) | |
| if((cell1.charCodeAt(1)%2!=0&&cell2.charCodeAt(1)%2!=0)||(cell1.charCodeAt(1)%2==0&&cell2.charCodeAt(1)%2==0)) | |
| return true; | |
| else | |
| return false; | |
| else | |
| if((cell1.charCodeAt(0)-64)%2!=0&&(cell2.charCodeAt(0)-64)%2!=0) | |
| if((cell1.charCodeAt(1)%2==0&&cell2.charCodeAt(1)%2==0)||(cell1.charCodeAt(1)%2!=0&&cell2.charCodeAt(1)%2!=0)) | |
| return true; |
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 alphabeticShift(inputString) { | |
| var shift=inputString.split(""); | |
| var shifted=shift.map((curr)=>{ | |
| if (curr=='z') | |
| return 'a'; | |
| else | |
| return String.fromCharCode(curr.charCodeAt(0)+1); | |
| }) | |
| return shifted.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 variableName(name) { | |
| return /^([a-z]|[A-Z]|_)([a-z]|[A-Z]|_|\d)*$/.test(name); | |
| } |
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 evenDigitsOnly(n) { | |
| var nums=n.toString().split(""); | |
| return nums.reduce((acc,currval,currindex,arr)=>{ | |
| return acc&&currval%2==0 | |
| },true); | |
| } |
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 arrayReplace(inputArray, elemToReplace, substitutionElem) { | |
| return inputArray.map((curr)=>{ | |
| if(curr==elemToReplace) | |
| return substitutionElem; | |
| else | |
| return curr; | |
| }); | |
| } |