-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
137 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
function anagramDifference(w1, w2) { | ||
let freq1 = {}; | ||
let freq2 = {}; | ||
let res = 0; | ||
for (let char of w1) { | ||
freq1[char] = (freq1[char] || 0) + 1; | ||
let rate1 = {}; | ||
let rate2 = {}; | ||
let listy = 0; | ||
for (let sign of w1) { | ||
rate1[sign] = (rate1[sign] || 0) + 1; | ||
} | ||
for (let char of w2) { | ||
freq2[char] = (freq2[char] || 0) + 1; | ||
for (let sign of w2) { | ||
rate2[sign] = (rate2[sign] || 0) + 1; | ||
} | ||
for (let char in freq1) { | ||
if (freq2[char]) { | ||
res += Math.abs(freq1[char] - freq2[char]); | ||
} else { | ||
res += freq1[char]; | ||
} | ||
for (let sign in rate1) { | ||
if (rate2[sign]) { | ||
listy += Math.abs(rate1[sign] - rate2[sign]); | ||
} else { | ||
listy += rate1[sign]; | ||
} | ||
} | ||
for (let char in freq2) { | ||
if (!freq1[char]) { | ||
res += freq2[char]; | ||
} | ||
for (let sign in rate2) { | ||
if (!rate1[sign]) { | ||
listy += rate2[sign]; | ||
} | ||
} | ||
return res; | ||
} | ||
return listy; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
function deepCount(a) { | ||
//... | ||
if (a.length === 0) { | ||
return 0; | ||
} | ||
let maxLength = 0; | ||
let mxLen = 0; | ||
for (let i = 0; i < a.length; i++) { | ||
if (Array.isArray(a[i])) { | ||
maxLength += deepCount(a[i]); | ||
mxLen += deepCount(a[i]); | ||
} | ||
maxLength++; | ||
mxLen++; | ||
} | ||
return maxLength; | ||
return mxLen; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
function towerBuilder(nFloors) { | ||
let stack = []; | ||
let maxWidth = nFloors * 2 - 1; | ||
let listy = []; | ||
let mxWid = nFloors * 2 - 1; | ||
for (let i = 0; i < nFloors; i++) { | ||
let stars = i * 2 + 1; | ||
let spaces = (maxWidth - stars) / 2; | ||
let floor = " ".repeat(spaces) + "*".repeat(stars) + " ".repeat(spaces); | ||
stack.push(floor); | ||
let spaces = (mxWid - stars) / 2; | ||
let level = " ".repeat(spaces) + "*".repeat(stars) + " ".repeat(spaces); | ||
listy.push(level); | ||
} | ||
return stack; | ||
return listy; | ||
} |
18 changes: 9 additions & 9 deletions
18
codewars/Convert string to camel case/ConvertStringToCamel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
function toCamelCase(str) { | ||
str = str.split(""); | ||
for (let i = 0; i < str.length; i++) { | ||
if (str[i] === "-" || str[i] === "_") { | ||
str.splice(i, 2, str[i + 1].toUpperCase()); | ||
} else { | ||
continue; | ||
} | ||
str = str.split(""); | ||
for (let i = 0; i < str.length; i++) { | ||
if (str[i] === "-" || str[i] === "_") { | ||
str.splice(i, 2, str[i + 1].toUpperCase()); | ||
} else { | ||
continue; | ||
} | ||
return str.join(""); | ||
} | ||
} | ||
return str.join(""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
function duplicateEncode(word) { | ||
let map = new Map(); | ||
let scheme = new Map(); | ||
let arr = word.toLowerCase().split(""); | ||
for (let item of arr) { | ||
if (map.has(item)) { | ||
map.set(item, map.get(item) + 1); | ||
if (scheme.has(item)) { | ||
scheme.set(item, scheme.get(item) + 1); | ||
} else { | ||
map.set(item, 1); | ||
scheme.set(item, 1); | ||
} | ||
} | ||
let res = []; | ||
let listy = []; | ||
for (let i = 0; i < arr.length; i++) { | ||
if (map.get(arr[i]) > 1) { | ||
res.push(")"); | ||
if (scheme.get(arr[i]) > 1) { | ||
listy.push(")"); | ||
} else { | ||
res.push("("); | ||
listy.push("("); | ||
} | ||
} | ||
return res.join(""); | ||
return listy.join(""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
function maxSum(root) { | ||
const maxSumRootToLeaf = (node) => { | ||
const FromBeginningToEnd = (node) => { | ||
if (node === null) { | ||
return 0; | ||
} | ||
if (node.left === null && node.right === null) { | ||
return node.value; | ||
} | ||
const leftSum = | ||
node.left !== null ? maxSumRootToLeaf(node.left) : -Infinity; | ||
node.left !== null ? FromBeginningToEnd(node.left) : -Infinity; | ||
const rightSum = | ||
node.right !== null ? maxSumRootToLeaf(node.right) : -Infinity; | ||
node.right !== null ? FromBeginningToEnd(node.right) : -Infinity; | ||
return node.value + Math.max(leftSum, rightSum); | ||
}; | ||
return maxSumRootToLeaf(root); | ||
return FromBeginningToEnd(root); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
function mergeArrays(a, b) { | ||
// your code here | ||
let left = 0; | ||
let right = 0; | ||
let res = []; | ||
let listy = []; | ||
while (left < a.length && right < b.length) { | ||
res.push(a[left]); | ||
listy.push(a[left]); | ||
left++; | ||
res.push(b[right]); | ||
listy.push(b[right]); | ||
right++; | ||
} | ||
while (left < a.length) { | ||
res.push(a[left]); | ||
listy.push(a[left]); | ||
left++; | ||
} | ||
while (right < b.length) { | ||
res.push(b[right]); | ||
listy.push(b[right]); | ||
right++; | ||
} | ||
return res; | ||
return listy; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
function moveZeros(arr) { | ||
let counter = 0; | ||
let newArr = []; | ||
let count = 0; | ||
let listy = []; | ||
for (let item of arr) { | ||
if (item === 0) { | ||
counter += 1; | ||
count += 1; | ||
} else { | ||
newArr.push(item); | ||
listy.push(item); | ||
} | ||
} | ||
for (let i = 0; i < counter; i++) { | ||
newArr.push(0); | ||
for (let i = 0; i < count; i++) { | ||
listy.push(0); | ||
} | ||
return newArr; | ||
return listy; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
function pigIt(str) { | ||
//Code here | ||
str = str.split(" "); | ||
let arr = []; | ||
for (let i = 0; i < str.length; i++) { | ||
let newStr = ""; | ||
let str1 = ""; | ||
if (str[i] === "!" || str[i] === "?") { | ||
newStr = str[i].split("").slice(1).concat(str[i][0]); | ||
str1 = str[i].split("").slice(1).concat(str[i][0]); | ||
} else { | ||
newStr = str[i].split("").slice(1).concat(str[i][0], "ay"); | ||
str1 = str[i].split("").slice(1).concat(str[i][0], "ay"); | ||
} | ||
arr.push(newStr.join("")); | ||
arr.push(str1.join("")); | ||
} | ||
return arr.join(" "); | ||
} |
Oops, something went wrong.