-
Notifications
You must be signed in to change notification settings - Fork 34
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
14 changed files
with
264 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function anagramDifference(w1,w2){ | ||
var count = 0; | ||
|
||
for (var i = 0; i < w1.length; i++){ | ||
if (w2.indexOf(w1[i]) >= 0){ | ||
|
||
w2 = w2.replace(w1[i], '') | ||
|
||
} else { | ||
|
||
count++ | ||
|
||
} | ||
} | ||
return w2.length + count | ||
} | ||
|
||
|
||
console.log(anagramDifference('codewars', 'hackerrank')) |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function deepCount(a){ | ||
var counter = 0 | ||
|
||
function recursive(a){ | ||
for (var i = 0; i < a.length; i++){ | ||
if (Array.isArray(a[i])){ | ||
counter++ | ||
recursive(a[i]) | ||
} else { | ||
counter++ | ||
} | ||
} | ||
} | ||
|
||
recursive(a) | ||
return counter | ||
} | ||
|
||
console.log(deepCount(["x", "y", ["z"]])) |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function towerBuilder(nFloor){ | ||
var towerArray = [] | ||
for (var i = 0; i < nFloor; i++){ | ||
var star = "*".repeat(1 + i * 2) | ||
var space = " ".repeat(nFloor - i - 1) | ||
var floor = space + star + space | ||
|
||
towerArray.push(floor) | ||
} | ||
return towerArray | ||
} | ||
|
||
console.log() |
12 changes: 12 additions & 0 deletions
12
codewars/Convert string to camel case/convertStringToCamesCase.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function toCamelCase(str){ | ||
|
||
var newStrArr = str.split(/[_-]/); | ||
for (var i = 1; i < newStrArr.length; i++){ | ||
newStrArr[i] = newStrArr[i][0].toUpperCase() + newStrArr[i].substring(1); | ||
} | ||
return newStrArr.join(''); | ||
} | ||
|
||
console.log(toCamelCase("the-stealth-warrior")) | ||
console.log(toCamelCase("The_Stealth_Warrior")) | ||
console.log(toCamelCase("The_Stealth-Warrior")) |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function duplicateEncode(word){ | ||
|
||
word = word.toLowerCase(); | ||
var newstr = ""; | ||
var count = 0; | ||
for (let i = 0; i < word.length; i++){ | ||
count = 0 | ||
for (let j = 0; j < word.length; j++){ | ||
if (word[j] === word[i]){ | ||
count ++ | ||
} | ||
} | ||
if (count > 1) { | ||
newstr += ")" | ||
} else { | ||
newstr += "(" | ||
} | ||
} | ||
return newstr | ||
} | ||
|
||
console.log(duplicateEncode('din')) | ||
console.log(duplicateEncode('recede')) | ||
console.log(duplicateEncode('Success')) | ||
console.log(duplicateEncode('(( @')) |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
array = ["O", "Q", "R", "S"] | ||
|
||
console.log(findMissingLetter(array)) | ||
|
||
function findMissingLetter(charArray){ | ||
var idx = 0 | ||
firstLetter = charArray[0].charCodeAt(idx) | ||
for (var i = 1; i < charArray.length; i++){ | ||
currentLetter = charArray[i].charCodeAt(idx) | ||
if (1 < currentLetter - firstLetter){ | ||
return String.fromCharCode(firstLetter + 1) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var a = ['a', 'b', 'c', 'd', 'e'] | ||
|
||
var b = [1, 2, 3, 4, 5] | ||
|
||
function mergeArray(a, b) { | ||
|
||
var res = [] | ||
var biggestLengthOfArray = 0 | ||
if (a.length > b.length){ | ||
biggestLengthOfArray = a.length | ||
} else if (a.length == b.length){ | ||
biggestLengthOfArray = b.length | ||
} else { | ||
biggestLengthOfArray = b.length | ||
} | ||
|
||
for (var i = 0; i < biggestLengthOfArray; i++) { | ||
if (a[i] !== undefined) res.push(a[i]) | ||
if (b[i] !== undefined) res.push(b[i]) | ||
} | ||
|
||
return res | ||
} | ||
|
||
|
||
console.log(mergeArray(a, b)) |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const arr = [false,1,0,1,2,0,1,3,"a"] | ||
|
||
function moveZeros(arr) { | ||
var emptyArray = [] | ||
var counter = 0 | ||
|
||
for (var i = 0; i < arr.length; i++){ | ||
|
||
if (arr[i] !== 0){ | ||
emptyArray.push(arr[i]) | ||
} else { | ||
counter++ | ||
} | ||
} | ||
for (var j = 0; j < counter; j++){ | ||
emptyArray.push(0) | ||
} | ||
|
||
return emptyArray | ||
} | ||
|
||
console.log(moveZeros(arr)) |
17 changes: 17 additions & 0 deletions
17
codewars/Product of consecutive Fib numbers/productOfConsecutiveFibNumbers.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function productFib(prod) { | ||
|
||
var FibFirst = 0 | ||
var FibSecond = 1 | ||
|
||
while (FibFirst * FibSecond < prod){ | ||
const store = FibSecond | ||
FibSecond = FibSecond + FibFirst | ||
FibFirst = store | ||
|
||
} | ||
return [FibFirst, FibSecond, FibFirst * FibSecond === prod]; | ||
} | ||
|
||
|
||
console.log(productFib(714)) | ||
console.log(productFib(800)) |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function pigIt(str) { | ||
|
||
var words = str.split(' '); | ||
|
||
function convertWord(word) { | ||
if (/^[A-Za-z]+$/.test(word)) { | ||
return word.slice(1) + word[0] + 'ay'; | ||
} else { | ||
return word; | ||
} | ||
} | ||
|
||
var pigLatinWords = words.map(convertWord); | ||
|
||
var pigLatinStr = pigLatinWords.join(' '); | ||
|
||
return pigLatinStr; | ||
} |
27 changes: 27 additions & 0 deletions
27
codewars/Sum of Digits - Digital Root/sumOfDigitsDigitalRoot.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function digitalRoot(number){ | ||
|
||
var numberStr = String(number) | ||
numberStr = numberStr.split("") | ||
|
||
if (number > 9){ | ||
var sum = 0 | ||
for (var i = 0; i < numberStr.length; i++ ){ | ||
|
||
sum += Number(numberStr[i]) | ||
|
||
} | ||
|
||
return digitalRoot(sum) | ||
|
||
} else { | ||
|
||
return number | ||
|
||
} | ||
} | ||
|
||
console.log(digitalRoot(16)) | ||
console.log(digitalRoot(942)) | ||
console.log(digitalRoot(132189)) | ||
console.log(digitalRoot(493193)) | ||
console.log(digitalRoot(10)) |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function sumPairs(ints, s) { | ||
var second_index = +Infinity | ||
var answer = undefined; | ||
for (let i = 0; i < ints.length - 1; i++){ | ||
for (let j = i + 1; j < ints.length; j++){ | ||
if ((ints[i] + ints[j]) == s){ | ||
if (second_index > j){ | ||
second_index = j | ||
answer = [ints[i], ints[j]] | ||
} | ||
} | ||
} | ||
} | ||
return answer | ||
} | ||
|
||
console.log(sumPairs([10, 5, 2, 3, 7, 5], 10)) |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function validParentheses(parens) { | ||
var count = 0 | ||
for (i = 0; i < parens.length; i++){ | ||
if (parens[i] == '('){ | ||
count++ | ||
} else { | ||
count-- | ||
} | ||
} | ||
if (count == 0){ | ||
return true | ||
} | ||
return false | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function anagrams(word, words) { | ||
let answer = [] | ||
for (let words_key in words){ | ||
let candidate = words[words_key] | ||
let anagram = true | ||
for (let word_key in word){ | ||
if (words[words_key].indexOf(word[word_key]) >= 0){ | ||
words[words_key] = words[words_key].replace(word[word_key], '') | ||
} else { | ||
anagram = false | ||
break | ||
} | ||
} | ||
if (words[words_key].length == 0 && anagram){ | ||
answer.push(candidate) | ||
} | ||
} | ||
return answer | ||
} | ||
|
||
console.log(anagrams('racer', ['crazer', 'carer', 'racar', 'caers', 'racer'])) |