Skip to content

Instantly share code, notes, and snippets.

View RahmatSaeedi's full-sized avatar

Rahmat Saeedi RahmatSaeedi

View GitHub Profile
@RahmatSaeedi
RahmatSaeedi / sum.js
Created June 26, 2019 20:06
This JS file sums the input argumets and prints the sum to the console
// 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);
@RahmatSaeedi
RahmatSaeedi / add.js
Last active May 10, 2021 14:21
CodeSignal - Arcade - Intro - JS - add
function add(param1, param2) {
return param1+param2;
}
@RahmatSaeedi
RahmatSaeedi / centuryFromYear.js
Last active May 10, 2021 14:21
CodeSignal - Arcade - Intro - JS - centuryFromYear
function centuryFromYear(year) {
return Math.ceil(year/100);
}
@RahmatSaeedi
RahmatSaeedi / checkPalindrome.js
Last active May 10, 2021 14:21
CodeSignal - Arcade - Intro - JS - checkPalindrome
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;
}
@RahmatSaeedi
RahmatSaeedi / adjacentElementsProduct.js
Last active May 10, 2021 14:20
CodeSignal - Arcade - Intro - JS - adjacentElementsProduct
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;
@RahmatSaeedi
RahmatSaeedi / shapeArea.js
Last active May 10, 2021 14:19
CodeSignal - Arcade - Intro - JS - shapeArea
function shapeArea(n) {
return n**2 + (n-1)**2;
}
@RahmatSaeedi
RahmatSaeedi / Make Array Consecutive 2.js
Last active May 10, 2021 14:19
CodeSignal - Arcade - Intro - JS - Make Array Consecutive 2
function makeArrayConsecutive2(statues) {
return Math.max(...statues) - Math.min(...statues) - statues.length +1;
}
@RahmatSaeedi
RahmatSaeedi / almostIncreasingSequence.js
Last active May 10, 2021 14:19
CodeSignal - Arcade - Intro - JS - almostIncreasingSequence
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;
@RahmatSaeedi
RahmatSaeedi / matrixElementsSum.js
Last active May 10, 2021 14:19
CodeSignal - Arcade - Intro - JS - matrixElementsSum
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;
@RahmatSaeedi
RahmatSaeedi / All Longest Strings.js
Last active May 10, 2021 14:19
CodeSignal - Arcade - Intro - JS - All Longest Strings
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]);
}