Skip to content

Instantly share code, notes, and snippets.

View alexko30's full-sized avatar

Alexandr Kornienko alexko30

  • Kiev, Ukrane
View GitHub Profile
@alexko30
alexko30 / find Needle Element In Array Javascript
Last active May 6, 2018 12:21
find Needle Element In Array Javascript
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');
@alexko30
alexko30 / makeInitialsFromName
Created April 30, 2018 22:33
make Initials From Name
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, '');
@alexko30
alexko30 / sumOfPositAndNegatElem
Created April 30, 2018 22:34
sum Of Positive And Negative Elements
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];
}
}
@alexko30
alexko30 / firstCharUpperCase
Created April 30, 2018 22:35
first Char to Upper Case
function firstCharUpperCase(str) {
console.log(str.charAt(0).toUpperCase() + str.slice(1));
}
firstCharUpperCase('ukraine');
@alexko30
alexko30 / removeFirstAndSecondCharacter
Created April 30, 2018 22:36
remove First And Second Character From String
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);
}
@alexko30
alexko30 / sumTill
Last active April 30, 2018 22:40
sumTill
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;
@alexko30
alexko30 / yearCentury
Last active April 30, 2018 22:42
year Century
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;
@alexko30
alexko30 / cubicVolumeDifference
Created April 30, 2018 22:43
cubic Volume Difference
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];
}
@alexko30
alexko30 / findDigit
Created April 30, 2018 22:43
find Digit
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]);
}
@alexko30
alexko30 / automorphic
Created April 30, 2018 22:44
automorphic
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;