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

CodeWars_Fox class_RPGSAGA #7

Open
wants to merge 9 commits into
base: Tsyganov_Vladislav_Vasilevich
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

172 changes: 172 additions & 0 deletions .idea/workspace.xml

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

22 changes: 22 additions & 0 deletions codewars/Adding Big Numbers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function add(a, b) {
let result = ''
let carry = 0
let i = a.length - 1
let j = b.length - 1

while (i >= 0 || j >= 0 || carry > 0) {
const digit1 = i >= 0 ? parseInt(a[i]) : 0
const digit2 = j >= 0 ? parseInt(b[j]) : 0
const sum = digit1 + digit2 + carry

carry = Math.floor(sum / 10)
result = (sum % 10) + result

i--
j--
}

return result
}

add()
24 changes: 24 additions & 0 deletions codewars/Anagram difference/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function anagramDifference(w1,w2){
const charCount = {}
let deletedCount = 0

for (const char of w1) {
charCount[char] = (charCount[char] || 0) + 1
}

for (const char of w2) {
if (!charCount[char]) {
deletedCount++
} else {
charCount[char]--
}
}

for (const char in charCount) {
deletedCount += charCount[char]
}

return deletedCount
}

anagramDifference()
16 changes: 16 additions & 0 deletions codewars/Array Deep Count/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function deepCount(a){
let count = 0

a.forEach((el) => {
if (Array.isArray(el)) {
count += 1
count += deepCount(el)
}else {
count += 1
}
})

return count
}

deepCount()
18 changes: 18 additions & 0 deletions codewars/Build Tower/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function towerBuilder(nFloors) {
if (nFloors === 1) return ["*"]

let newList = "*".repeat(nFloors * 2 - 1).split("")
let resArr = []

for (i = 0; i < nFloors; i++) {
resArr.push(newList.join(''));

newList[i] = " "
newList[newList.length - 1 - i] = " "
}


return resArr.reverse();
}

towerBuilder()
11 changes: 11 additions & 0 deletions codewars/Convert string to camel case/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function toCamelCase(str){
const words = str.split(/[-_]/)

for (i = 1; i < words.length; i++) {
words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1)
}

return words.join('')
}

toCamelCase()
22 changes: 22 additions & 0 deletions codewars/Duplicate Encoder/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function duplicateEncode(word){
const lowWord = word.toLowerCase()
const charCountMap = new Map()

let newStr = ""

for (const char of lowWord) {
charCountMap.set(char, (charCountMap.get(char) || 0) + 1);
}

for (const char of lowWord) {
if (charCountMap.get(char) === 1) {
newStr += '(';
} else {
newStr += ')';
}
}

return newStr;
}

duplicateEncode()
11 changes: 11 additions & 0 deletions codewars/Find the missing letter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function findMissingLetter(array) {
let firstlet = array[0].charCodeAt(0)

for (i = 1; i < array.length; i++) {
if (firstlet + i !== array[i].charCodeAt(0)) {
return String.fromCharCode(firstlet + i)
}
}
}

findMissingLetter()
29 changes: 29 additions & 0 deletions codewars/Flatten a Nested Map/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function flattenMap(map) {
const resObj = {}

if (Object.keys(map).length === 0) return {}

const recurseMap = (obj, path) => {

if (Array.isArray(obj) || obj === null) {
resObj[path.join('/')] = obj
}

else {
for (const key in obj) {
const newPath = path.concat(key)
if (typeof obj[key] === 'object') {
recurseMap(obj[key], newPath);
} else {
resObj[newPath.join('/')] = obj[key]
}
}
}
}

recurseMap(map, [])

return resObj
}

flattenMap()
2 changes: 1 addition & 1 deletion codewars/Fun with tree - max sum/.gitkeep
Original file line number Diff line number Diff line change
@@ -1 +1 @@

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

function dfs(node, currentSum) {
if (!node) {
return currentSum;
}

currentSum += node.value;

if (!node.left && !node.right) {
return currentSum;
}

const leftSum = dfs(node.left, currentSum);
const rightSum = dfs(node.right, currentSum);

return Math.max(leftSum, rightSum);
}

return dfs(root, 0);
}

maxSum()
Loading