Skip to content

Instantly share code, notes, and snippets.

View risingBirdSong's full-sized avatar

peter risingBirdSong

  • PNW
View GitHub Profile
class CircularArray<T> {
constructor(public arr: T[], public idx : number){}
next (){
if (this.idx == this.arr.length-1){
this.idx = 0;
}
else this.idx ++;
}
function duplicateEncode(word){
return word
.toLowerCase()
.split('')
.map( function (a, i, w) {
return w.indexOf(a) == w.lastIndexOf(a) ? '(' : ')'
})
.join('');
}
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;
}
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;
}
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;
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);
}
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
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;
@risingBirdSong
risingBirdSong / diamond.ts
Created December 29, 2019 03:34
code war katas
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';
@risingBirdSong
risingBirdSong / points.ts
Created December 29, 2019 03:33
code war kata "points"
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
}