Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sev pol #97

Open
wants to merge 11 commits into
base: Korotkov_Mihail_Aleksandrovich
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions codewars/Adding Big Numbers/AddingBigNumbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function add(a, b) {
while (a.length < b.length) a = '0' + a;
while (b.length < a.length) b = '0' + b;
let c = 0;
let d = '';
for (let i = a.length - 1; i >= 0; i--) {
let sum = Number(a[i]) + Number(b[i]) + c;
c = Math.floor(sum / 10);
d = (sum % 10) + d;
}
if (c > 0) {
d = c + d;
}
return d;
}
13 changes: 13 additions & 0 deletions codewars/Array Deep Count/ArrayDeepCount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function deepCount(a) {
let b = 0;
function Counter(c) {
for(let i of c) {
b++;
if (Array.isArray(i)) {
Counter(i);
}
}
}
Counter(a);
return b;
}
9 changes: 9 additions & 0 deletions codewars/Build Tower/BuildTower.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const towerBuilder = (nFloors: number): string[] => {
let a: string[] = [];
for (let i: number = 0; i < nFloors; i++) {
let b: string = ' '.repeat(nFloors-i-1);
let c: string = '*'.repeat(2*i+1);
a.push(b+c+b);
}
return a;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function toCamelCase(str: string): string {
let a: string[] = str.split(/[_-]/);
for (let i: number = 1; i<a.length; i++) {
a[i] = a[i][0].toUpperCase() + a[i].slice(1);
}
return a.join('');
}
12 changes: 12 additions & 0 deletions codewars/Duplicate Encoder/DuplicateEncoder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function duplicateEncode(word: string): string {
let a: string = "";
word = word.toLowerCase();
for (let i of word) {
if (word.split(i).length>2) {
a += ")"
} else {
a += "("
}
}
return a;
}
7 changes: 7 additions & 0 deletions codewars/Find the missing letter/FindTheMissingLetter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function findMissingLetter(array: string[]): string | void {
for (let i in array) {
if (array[i].charCodeAt(0)+1 !== array[Number(i)+1].charCodeAt(0)) {
return String.fromCharCode(array[i].charCodeAt(0)+1)
}
}
}
15 changes: 15 additions & 0 deletions codewars/Flatten a Nested Map/FlatterANestedMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function flattenMap(map) {
function remake(obj, key, res) {
for (let k in obj) {
let newKey = key ? `${key}/${k}` : k;
if (typeof obj[k] === 'object' && obj[k] !== null && !Array.isArray(obj[k])) {
remake(obj[k], newKey, res);
} else {
a[newKey] = obj[k];
}
}
}
let a = {};
remake(map, '', a);
return a;
}
27 changes: 27 additions & 0 deletions codewars/Fun with tree - max sum/FunWithTree_MaxSum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class TreeNode {
constructor(value, left = null, right = null) {
this.value = value;
this.left = left;
this.right = right;
}
}

function maxSum(root) {
if (root === null) {
return 0;
}
function findMaxSum(node) {
if (node.left === null && node.right === null) {
return node.value;
}
let maxSum = -Infinity;
if (node.left !== null) {
maxSum = Math.max(maxSum, findMaxSum(node.left));
}
if (node.right !== null) {
maxSum = Math.max(maxSum, findMaxSum(node.right));
}
return node.value + maxSum;
}
return findMaxSum(root)
}
13 changes: 13 additions & 0 deletions codewars/Merge two arrays/MergeTwoArrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function mergeArrays(a, b) {
c = [];
max = a.length>b.length ? a.length : b.length;
for (let i = 0; i<max; i++) {
if (a[i] !== undefined) {
c.push(a[i]);
}
if (b[i] !== undefined) {
c.push(b[i]);
}
}
return c;
}
13 changes: 13 additions & 0 deletions codewars/Moving Zeros To The End/MovingZerosToTheEnd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function moveZeros(arr) {
let a = [];
let count = 0;
for (let i of arr) {
if (i !== 0) {
a.push(i);
} else {
count += 1;
}
}
a.push(...new Array(count).fill(0));
return a;
}
20 changes: 20 additions & 0 deletions codewars/Permutations/SoManyPermutations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function permutations(string) {
function perm(arr, n, res) {
if (n === 1) {
res.add(arr.join(''));
} else {
for (let i = 0; i < n; i++) {
perm(arr, n - 1, res);
if (n % 2 === 0) {
[arr[i], arr[n - 1]] = [arr[n - 1], arr[i]];
} else {
[arr[0], arr[n - 1]] = [arr[n - 1], arr[0]];
}
}
}
}
let a = new Set();
let b = string.split('');
perm(b, b.length, a);
return Array.from(a);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const productFib = (prod: number): [number, number, boolean] => {
let a: number = 0;
let b: number = 1;
while (a*b < prod) {
let c: number = a + b;
a = b;
b = c;
}
return [a, b, a*b === prod];
}
10 changes: 10 additions & 0 deletions codewars/Sum of Digits - Digital Root/SumOfDigits_DigitalRoot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const digitalRoot = (n: number): number => {
while (n>9) {
let a: string = n.toString();
n = 0;
for (let i of a) {
n += Number(i);
}
}
return n;
};
12 changes: 12 additions & 0 deletions codewars/Sum of pairs/SumOfPairs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function sumPairs(ints: number[], s: number): [number, number] | void {
const a = new Map<number, number>();
for (let i: number = 0; i < ints.length; i++) {
const n: number = ints[i];
const c: number = s - n;
if (a.has(c)) {
return [c, n];
}
a.set(n, i);
}
return undefined;
}
14 changes: 14 additions & 0 deletions codewars/Valid Parentheses/ValidParentheses(retired).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function validParentheses(parens) {
let a = 0;
for(let i of parens) {
if (i === '(') {
a++;
} else if (i===')') {
a--;
if (a<0) {
return false;
}
}
}
return a === 0;
}
4 changes: 4 additions & 0 deletions codewars/Where my anagrams at/WhereMyAnagramsAt(retired).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function anagrams(word, words) {
let a = word.split('').sort().join('');
return words.filter(w => w.split('').sort().join('') === a);
}
Loading
Loading