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 absoluteValuesSumMinimization(a) { | |
let sum = a.map( i => distanceCalculator(a, i)); | |
let sumMin = sum.slice().sort((a,b) => a-b)[0]; | |
return a[sum.indexOf(sumMin)]; | |
} | |
function distanceCalculator(a, val){ | |
return a.map(i => Math.abs(i-val)).reduce((sum, num) => sum + num); |
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 depositProfit(deposit, rate, threshold) { | |
return Math.ceil(Math.log(parseFloat(threshold)/parseFloat(deposit)) / Math.log(1 + parseFloat(rate)/100.0)); | |
} |
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 circleOfNumbers(n, firstNumber) { | |
return (n/2+firstNumber) % n; | |
} |
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 chessBoardCellColor(cell1, cell2) { | |
return (cell1.charCodeAt(0) - cell2.charCodeAt(0) + cell1.charCodeAt(1) - cell2.charCodeAt(1)) %2 == 0; | |
} |
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 alphabeticShift(inputString) { | |
return inputString.split("").map( c => { | |
if(c == 'z') | |
c = 'a'; | |
else | |
c = String.fromCharCode(c.charCodeAt(0) + 1); | |
return c; | |
}).join(""); | |
} |
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 variableName(name) { | |
return name.match(/^[A-Za-z_][A-Za-z_0-9]*$/) != null ? true : false; | |
} |
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 evenDigitsOnly(n) { | |
return n.toString().split("").every((n) => (parseInt(n) % 2 == 0)); | |
} |
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 arrayReplace(inputArray, elemToReplace, substitutionElem) { | |
return inputArray.map(i => i==elemToReplace? substitutionElem: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 minesweeper(matrix) { | |
let height = matrix.length; | |
let width = matrix[0].length; | |
let outArray = Array.from(Array(height), () => new Array(width)); | |
let mines = 0; | |
for(let i = 0; i < height; i++) { | |
for(let j = 0; j < width; 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 boxBlur(image) { | |
let bluredImage = Array.from(Array(image.length-2), () => new Array(image[0].length-2)); | |
for(let i = 1; i < image.length-1; i++) { | |
for(let j = 1; j < image[i].length-1; j++){ | |
bluredImage[i-1][j-1] = Math.floor(( | |
image[i-1][j-1] + image[i-1][j] + image[i-1][j+1] + | |
image[i][j-1] + image[i][j] + image[i][j+1] + | |
image[i+1][j-1] + image[i+1][j] + image[i+1][j+1] |
NewerOlder