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

Completed tasks #76

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не там разместили файлы + гитигнор настраивайте

"presets": ["@babel/preset-env", "@babel/preset-react"]
}
17 changes: 17 additions & 0 deletions codewars/Adding Big Numbers/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function add(a, b) {
let result = [];
let carry = 0;
let maxLength = Math.max(a.length, b.length);
for (let i = 0; i < maxLength; i++) {
let digitA = parseInt(a[a.length - i - 1], 10) || 0;
let digitB = parseInt(b[b.length - i - 1], 10) || 0;
let summ = digitA + digitB + carry;
carry = Math.floor(summ / 10);
result.push((summ % 10).toString());
}

if (carry > 0) {
result.push(carry.toString());
}
return result.reverse().join('');
}
22 changes: 22 additions & 0 deletions codewars/Anagram difference/anagramdifference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function countChars(word) {
const count = {};
for (const char of word) {
count[char] = (count[char] || 0) + 1;
}
return count;
}

function anagramDifference(word1, word2) {
const count1 = countChars(word1);
const count2 = countChars(word2);
let totalRemovals = 0;
const allChars = new Set([...Object.keys(count1), ...Object.keys(count2)]);

for (const char of allChars) {
const freq1 = count1[char] || 0;
const freq2 = count2[char] || 0;
totalRemovals += Math.abs(freq1 - freq2);
}

return totalRemovals;
}
22 changes: 22 additions & 0 deletions codewars/Array Deep Count/anagramdifference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function countChars(word) {
const count = {};
for (const char of word) {
count[char] = (count[char] || 0) + 1;
}
return count;
}

function anagramDifference(word1, word2) {
const count1 = countChars(word1);
const count2 = countChars(word2);
let totalRemovals = 0;
const allChars = new Set([...Object.keys(count1), ...Object.keys(count2)]);

for (const char of allChars) {
const freq1 = count1[char] || 0;
const freq2 = count2[char] || 0;
totalRemovals += Math.abs(freq1 - freq2);
}

return totalRemovals;
}
12 changes: 12 additions & 0 deletions codewars/Array Deep Count/countelement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function countElements(arr) {
let count = 0;

for (let element of arr) {
count++;
if (Array.isArray(element)) {
count += countElements(element);
}
}

return count;
}
12 changes: 12 additions & 0 deletions codewars/Build Tower/buildTower.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import "strings"

func buildTower(numberOfFloors int) []string {
tower := make([]string, numberOfFloors)
for i := 1; i <= numberOfFloors; i++ {
floor := strings.Repeat(" ", numberOfFloors-i) + strings.Repeat("*", 2*i-1) + strings.Repeat(" ", numberOfFloors-1)
tower[i-1] = floor
}
return tower
}
16 changes: 16 additions & 0 deletions codewars/Convert string to camel case/camelCase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import "strings"

func camelCase(s string) string {
words := strings.Split(strings.Replace(s, "-", "_", -1), "_")
var result string
for i, word := range words {
if i == 0 {
result += word
} else {
result += strings.Title(word)
}
}
return result
}
20 changes: 20 additions & 0 deletions codewars/Duplicate Encoder/duplicateEncoder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import "strings"

func duplicateEncoder(word string) string {
word = strings.ToLower(word)
counts := make(map[rune]int)
for _, char := range word {
counts[char]++
}
var result strings.Builder
for _, char := range word {
if counts[char] == 1 {
result.WriteString("(")
} else {
result.WriteString(")")
}
}
return result.String()
}
10 changes: 10 additions & 0 deletions codewars/Find the missing letter/findTheMissingLetter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

func findMissingLetter(chars []rune) rune {
for i := 0; i < len(chars)-1; i++ {
if chars[i+1] != chars[i]+1 {
return chars[i] + 1
}
}
return 0
}
19 changes: 19 additions & 0 deletions codewars/Flatten a Nested Map/flattenMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function flattenMap(map, prefix = '') {
const result = {};

for (const key in map) {
if (map.hasOwnProperty(key)) {
const value = map[key];
const newKey = prefix ? `${prefix}/${key}` : key;

if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
const nested = flattenMap(value, newKey);
Object.assign(result, nested);
} else {
result[newKey] = value;
}
}
}

return result;
}
13 changes: 13 additions & 0 deletions codewars/Fun with tree - max sum/funWithTreeMaxSum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function maxSum(root) {
if (!root) return 0;

if(!root.left && !root.right) return root.value;

let leftMax = -Infinity;
let rightMax = -Infinity;

if (root.left) leftMax = maxSum(root.left);
if (root.right) rightMax = maxSum(root.right);

return root.value + Math.max(leftMax, rightMax);
}
23 changes: 23 additions & 0 deletions codewars/Linked Lists - Sorted Insert/sortedInsert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function Node(data) {
this.data = data;
this.next = null;
}

function sortedInsert(head, data) {
let newNode = new Node(data);

if (!head || data < head.data) {
newNode.next = head;
return newNode;
}

let current = head;
while (current.next && current.next.data < data) {
current = current.next;
}

newNode.next = current.next;
current.next = newNode;

return head;
}
12 changes: 12 additions & 0 deletions codewars/Moving Zeros To The End/movingZeros.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

func movingZeros(array []int) []int {
nonZero := 0
for i := 0; i < len(array); i++ {
if array[i] != 0 {
array[nonZero], array[i] = array[i], array[nonZero]
nonZero++
}
}
return array
}
13 changes: 13 additions & 0 deletions codewars/Sum of Digits - Digital Root/digitalRoot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

func digitalRoot(number int) int {
for number >= 10 {
summ := 0
for number != 0 {
summ += number % 10
number /= 10
}
number = summ
}
return number
}
37 changes: 37 additions & 0 deletions codewars/Tic-Tac-Toe Checker/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import "fmt"

func isSolved(board [3][3]int) int {
for i := 0; i < 3; i++ {
if board[i][0] == board[i][1] && board[i][1] == board[i][2] && board[i][0] != 0 {
return board[i][0]
}
if board[0][i] == board[1][i] && board[1][i] == board[2][i] && board[i][0] != 0 {
return board[0][i]
}
}

if board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[0][0] != 0 {
return board[0][0]
}

if board[0][2] == board[1][1] && board[1][1] == board[2][0] && board[0][2] != 0 {
return board[0][2]
}

for i := 0; i < 3; i++ {
for j := 0; j < 3; j++ {
if board[i][j] == 0 {
return -1
}
}
}
return 0
}

func main() {
board := [3][3]int{{0, 2, 1}, {2, 0, 1}, {0, 2, 1}}
fmt.Println(isSolved(board))

}
11 changes: 11 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.jsx?$': 'babel-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
testMatch: ['**/?(*.)+(spec|test).[tj]s?(x)'],
setupFilesAfterEnv: ['<rootDir>/setupTests.ts'],
};
15 changes: 15 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
preset: 'ts-jest',
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.jsx?$': 'babel-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
testMatch: ['**/?(*.)+(spec|test).[tj]s?(x)'],
setupFilesAfterEnv: ['<rootDir>/setupTests.ts'],
};

export default config;
1 change: 1 addition & 0 deletions node_modules/.bin/acorn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/browserslist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/create-jest

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/ejs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/esparse

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/esvalidate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/import-local-fixture

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/jake

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/jest

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/jsesc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/loose-envify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/lz-string

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/node-which

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/opencollective

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/parser

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/regjsparser

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/resolve

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/ts-jest

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/ts-node

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/ts-node-cwd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/ts-node-esm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/ts-node-script

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/ts-node-transpile-only

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/ts-script

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/tsc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/tsserver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/update-browserslist-db

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading