-
Notifications
You must be signed in to change notification settings - Fork 85
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
base: Grigorev_Aleksandr_Konstantinovich
Are you sure you want to change the base?
Completed tasks #76
Changes from 2 commits
aed512f
2a2ec31
a593cca
1c2c3fb
c48eb6c
f58e02a
b223fa1
2486c66
4455b0c
b67e514
50ba96a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["@babel/preset-env", "@babel/preset-react"] | ||
} |
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(''); | ||
} |
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; | ||
} |
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; | ||
} |
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; | ||
} |
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 | ||
} |
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 | ||
} |
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() | ||
} |
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 | ||
} |
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; | ||
} |
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); | ||
} |
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; | ||
} |
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 | ||
} |
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 | ||
} |
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)) | ||
|
||
} |
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'], | ||
}; |
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; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не там разместили файлы + гитигнор настраивайте