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
class CircularArray<T> { | |
constructor(public arr: T[], public idx : number){} | |
next (){ | |
if (this.idx == this.arr.length-1){ | |
this.idx = 0; | |
} | |
else this.idx ++; | |
} |
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
function duplicateEncode(word){ | |
return word | |
.toLowerCase() | |
.split('') | |
.map( function (a, i, w) { | |
return w.indexOf(a) == w.lastIndexOf(a) ? '(' : ')' | |
}) | |
.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
function findEvenIndex(arr) | |
{ | |
for(var i=1; i<arr.length-1; i++) { | |
if(arr.slice(0, i).reduce((a, b) => a+b) === arr.slice(i+1).reduce((a, b) => a+b)) { | |
return i; | |
} | |
} | |
return -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
function duplicateCounta(text : string){ | |
return text | |
.toLowerCase() | |
.split('') | |
.reduce(function(a, l) { | |
a[l] = a[l] ? a[l]+1 : 1; | |
if(a[l] === 2) a.count++; | |
return a; | |
}, {count:0}).count; | |
} |
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
function cleanString(s: string) { | |
let arrayed = s.split(''); //? | |
let index = 0; | |
while (index < arrayed.length) { | |
arrayed | |
if (arrayed[index] == "#") { | |
if (index == 0) { | |
arrayed.splice(index, 1); | |
index = 0; | |
continue; |
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
function accum(s:string){ | |
return s.split('').map((letter, idx)=>{ | |
let output = letter.repeat(idx + 1).toLowerCase(); | |
return capitalizeFirstLetter(output); | |
}).join('-') | |
} | |
function capitalizeFirstLetter(string : string) { | |
return string.charAt(0).toUpperCase() + string.slice(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
function enhancedCoin (cents:number){ | |
return [25,10,5,1].map((denomination) => { | |
let c = Math.floor(cents / denomination); | |
cents %= denomination; | |
return c; | |
}).reverse() | |
} | |
// saw this and reimplemented it... a great code wars solution by another code 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
const coinCombo = function(cents : number) { | |
let change : [penny, nickel, dime, quarter] = [0,0,0,0]; | |
let quarters, dimes, nickels, pennies; | |
if (cents / 25 >= 1) { | |
quarters = Math.floor(cents / 25); | |
cents -= 25 * quarters; | |
} | |
if (cents / 10 >= 1) { | |
dimes = Math.floor(cents / 10) | |
cents -= 10 * dimes; |
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
function diamond(n : number){ | |
if (n < 0 || n % 2 == 0){ | |
return null; | |
} | |
let diamondstring = ''; | |
for (let i = 1; i <= n; i += 2){ | |
diamondstring += ' '.repeat((n - i) / 2) + '*'.repeat(i) + '\n'; | |
} | |
for (let i = n - 2; i > 0; i -= 2){ | |
diamondstring += ' '.repeat((n - i) / 2) + '*'.repeat(i) + '\n'; |
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
function points(games : string[]){ | |
let ourpoints = 0; | |
games.forEach((val) => { | |
let split = val.split(":"); //? | |
if (split[0] > split[1]){ | |
ourpoints += 3 | |
} | |
else if (split[0] == split[1]){ | |
ourpoints += 1 | |
} |
NewerOlder