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
// This JS file sums the input argumets and prints the sum to the console | |
// Example | |
// node sum 1 2 | |
// 3 | |
// node sum 10 -100 12 | |
// 102 | |
// | |
// jshint esversion: 6 | |
const args = process.argv.slice(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 add(param1, param2) { | |
return param1+param2; | |
} |
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 centuryFromYear(year) { | |
return Math.ceil(year/100); | |
} |
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 checkPalindrome(inputString) { | |
for(let i = 0; i<Math.floor(inputString.length/2); i++) { | |
if(inputString[i] != inputString[inputString.length - i-1]){ | |
return false; | |
} | |
} | |
return true; | |
} |
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) { | |
let product = inputArray[0]*inputArray[1]; | |
if(inputArray.length === 2) { | |
return product; | |
} else { | |
for(let i = 1; i < inputArray.length - 1; i++) { | |
product=Math.max(product, inputArray[i] * inputArray[i+1]); | |
} | |
return product; |
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 n**2 + (n-1)**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 makeArrayConsecutive2(statues) { | |
return Math.max(...statues) - Math.min(...statues) - statues.length +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 almostIncreasingSequence(sequence) { | |
let wasAnElementRemoved = false; | |
for(let i = 0; i<sequence.length-1; i++) { | |
if(sequence[i] < sequence[i+1]) { | |
continue; | |
} else { | |
if(!wasAnElementRemoved) { | |
wasAnElementRemoved = true; | |
if(i==0) { | |
continue; |
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) { | |
let sum = 0 ; | |
for(let j = 0; j < matrix[0].length; j++) { | |
let i = 0; | |
while(i < matrix.length && matrix[i][j] != 0 ){ | |
sum += matrix[i][j]; | |
i++; | |
} | |
} | |
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 allLongestStrings(inputArray) { | |
let returnArray=['']; | |
for(let i = 0; i<inputArray.length; i++){ | |
if(inputArray[i].length > returnArray[0].length) { | |
returnArray = []; | |
returnArray.push(inputArray[i]); | |
} else if(inputArray[i].length == returnArray[0].length) { | |
returnArray.push(inputArray[i]); | |
} |
OlderNewer