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 findNeedleElement(arr, element) { | |
for (let i = 0; i < arr.length; i++) { | |
if(arr[i] == element) { | |
console.log(arr); | |
console.log(`Needle element is found at ${i} posotion: ${element}`); | |
} | |
} | |
} | |
findNeedleElement(['petya', 'gus', 'sashko', 'alex', 'gena', 'german'], 'german'); |
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 makeInitialsFromName(strName) { | |
const arrName = strName.split(''); | |
const firstLetter = strName.charAt(0).toUpperCase(); | |
let arrInitials = []; | |
arrInitials.splice(0, 0, firstLetter, '. ') | |
for (var i = 0; i < arrName.length; i++) { | |
if (arrName[i] == ' ') { | |
const secondLetter = arrName[i + 1].toUpperCase(); | |
arrInitials.splice(0, 0, secondLetter, '.'); | |
const initials = arrInitials.toString().replace(/,/g, ''); |
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 sumOfPositAndNegatElem(arr) { | |
let positiveSum = 0; | |
let negativeSum = 0; | |
for (let i = 0; i < arr.length; i++) { | |
if (arr[i] < 0 || arr[i] == 0) { | |
negativeSum += arr[i]; | |
} else if (arr[i] > 0) { | |
positiveSum += arr[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 firstCharUpperCase(str) { | |
console.log(str.charAt(0).toUpperCase() + str.slice(1)); | |
} | |
firstCharUpperCase('ukraine'); |
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 removeFirstAndSecondCharacter(str) { | |
const strArray = str.split(''); | |
const firstStarrPoint = 0; | |
strArray.splice(firstStarrPoint, 1); | |
strArray.pop(); | |
let strNew = strArray.toString().replace(/,/g, ''); | |
console.log(strNew); | |
} |
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 sumTill(start, till) { | |
if(start < till && till > 0) { | |
let step = start; | |
let result = start; | |
let resultArray = []; | |
resultArray.push(result); | |
for (let i = 0; i < till; i++) { | |
result += step; |
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 yearCentury(year) { | |
if (year >= 1 && year <= 100) { | |
console.log(1, 'century'); | |
} else { | |
const yearArray = String(year).split(''); | |
const arrayPoint = yearArray.length - 2; | |
let checkValue = 0; | |
for (var i = arrayPoint; i < yearArray.length; i++) { | |
if (yearArray[i] == 0) { | |
checkValue += 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 cubicVolumeDifference(cub1, cub2) { | |
let cubSum1 = 1; | |
let cubSum2 = 1; | |
for (let i = 0; i < cub1.length; i++) { | |
cubSum1 *= cub1[i]; | |
} | |
for (let i = 0; i < cub2.length; i++) { | |
cubSum2 *= cub2[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 findDigit(number, nth) { | |
if(nth <= 0) { | |
console.log(-1); | |
} else { | |
const digits = (""+number).split(""); | |
const digitLength = digits.length; | |
const ourNumIndex = digitLength - nth; | |
console.log(digits[ourNumIndex]); | |
} |
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 automorphic(number) { | |
const numberArr = Array.from(number.toString()).map(Number); | |
const square = Math.pow(number, 2); | |
const squareArr = Array.from(square.toString()).map(Number); | |
const startElement = squareArr.length - numberArr.length; | |
let flag = false; | |
for (let i = 0, j = startElement; i < numberArr.length, j < squareArr.length; i++, j++) { | |
flag = false; |
OlderNewer