Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
39 changes: 39 additions & 0 deletions codewars/Adding Big Numbers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function add(a, b) {
let sum = "";

if (a.length > b.length) {
l = a.length - b.length;

for (let i = 0; i < l; i++) {
b = "0" + b;
}
}

if (a.length < b.length) {
l = b.length - a.length;

for (let i = 0; i < l; i++) {
a = "0" + a;
}
}

let step = [];
for (let i = a.length - 1; i >= 0; i--) {
let A = Number(a[i]);
let B = Number(b[i]);
let result = A+B;
if (step[i + 1]) {
result = step[i + 1] + A + B;
} else {
result = A + B;
}
if (result >= 10 && i !== 0) {
sum = String(result - 10) + sum;
step[i] = 1;
} else {
sum = String(result) + sum;
}
}

return sum;
}
20 changes: 20 additions & 0 deletions codewars/Anagram difference/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function anagramDifference(w1,w2){
let map = new Map();
let count = 0;
let l = (w1+w2).length;
for (let i of w1) {
map.set(i, (map.get(i) || 0)+1);
}

for (let i of w2){
map.set(i, (map.get(i) || 0)-1);
}

for (let [key, value] of map) {
count += Math.abs(value);
}



return count;
}
8 changes: 8 additions & 0 deletions codewars/Array Deep Count/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function deepCount(arr){
let k = arr.length;
for (const elm of arr)
{
k += Array.isArray(elm) ? deepCount(elm) : 0;
}
return k;
}
7 changes: 7 additions & 0 deletions codewars/Build Tower/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function towerBuilder(nFloors) {
res = [];
for (let i = 1; i <= nFloors; i++) {
res.push(" ".repeat(nFloors - i) + "*".repeat(i * 2 - 1) + " ".repeat(nFloors - i));
}
return res;
}
12 changes: 12 additions & 0 deletions codewars/Convert string to camel case/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function toCamelCase(str){
str = str.split("");
for (let i = 0; i < str.length; i++) {
if (str[i] === "-" || str[i] === "_"){
str.splice(i, 1);
str[i] = str[i].toUpperCase();
}
}
str = str.join("")

return str
}
26 changes: 26 additions & 0 deletions codewars/Duplicate Encoder/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function duplicateEncode(word){
let map = new Map();
word = word.toLowerCase()
str = ""
for (let i = 0; i < word.length; i++) {
count = 0
for (let j = 0; j < word.length; j++) {
if (word[i] === word[j]){
count += 1;
}
}
map.set(word[i], count);
}



for (let i = 0; i < word.length; i++) {
if (map.get(word[i]) > 1 ){
str += ")"
} else {
str += "("
}
}
return str

}
10 changes: 10 additions & 0 deletions codewars/Find the missing letter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function findMissingLetter(array) {
let alphabetArr = Array.from('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
for (let i = 0; i < array.length - 1; i++){
for (let j = 0; j < alphabetArr.length - 1; j++) {
if (array[i] !== alphabetArr[j] && array[i+1] === alphabetArr[j+1]) {
return alphabetArr[j]
}
}
}
}
24 changes: 24 additions & 0 deletions codewars/Merge two arrays/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function mergeArrays(a, b) {
let newArray = [];
if (a.length > b.length) {

for (let i = 0; i < a.length; i++) {
if (a[i] !== undefined) {
newArray.push(a[i])
}
if (b[i] !== undefined) {
newArray.push(b[i])
}
}
} else {
for (let i = 0; i < b.length; i++) {
if (a[i] !== undefined) {
newArray.push(a[i])
}
if (b[i] !== undefined) {
newArray.push(b[i])
}
}
}
return newArray
}
9 changes: 9 additions & 0 deletions codewars/Moving Zeros To The End/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function moveZeros (arr) {
for (let i = arr.length - 1; i >= 0; i--) {
if (arr[i] === 0) {
arr.splice(i, 1);
arr.push(0);
}
}
return arr;
}
16 changes: 16 additions & 0 deletions codewars/Product of consecutive Fib numbers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function productFib(prod){
let a = 0;
let b = 1;

while (a*b<prod) {
let preva = a;

a = b;
b += preva;
console.log(a);
console.log(b);

}

return [a, b, a*b === prod]
}
13 changes: 13 additions & 0 deletions codewars/Simple Pig Latin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function pigIt(str){
let words = str.split(' ');
let pigLatin = [];

for(let word of words){
if((/([a-zA-Z])/).test(word)){
pigLatin.push(word.substring(1) + word[0] + "ay");
}else{
pigLatin.push(word);
}
}
return pigLatin.join(" ");
}
5 changes: 5 additions & 0 deletions codewars/Sum of Digits - Digital Root/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function digitalRoot(n) {

return (n-1) % 9 + 1

}
13 changes: 13 additions & 0 deletions codewars/Sum of pairs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function sumPairs(ints, s) {
if (ints.length<2) return undefined
let set = new Set()
for (let i = 0; i < ints.length; i++) {
let num = s-ints[i];
if (set.has(num)) {
return [num, ints[i]]
}
set.add(ints[i]);
}
return undefined

}
6 changes: 6 additions & 0 deletions codewars/package-lock.json

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

60 changes: 60 additions & 0 deletions rpgsaga/saga/src/OldFiles/cat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
export class Cat {
name: string;
color: string;
private aGe: number;

feedCount = 0;
petting = 0;

constructor(name: string, age: number, color: string, public weight?: number) {
this.name = name;
this.age = age;
this.color = color;
this.weight = this.weight > 0.5 && this.weight <= 10 ? this.weight : 3.5;
}

meow(): string {
return 'Мяу';
}

information(): string {
return `name: ${this.name} age: ${this.age} color:${this.color}`;
}

feed(): string {
if (this.feedCount <= 3) {
this.weight += 0.1;
this.feedCount += 1;
return `${this.name} съела ${this.feedCount} порцию(ций) и её вес увеличился на ${this.feedCount * 0.1}`;
} else {
return `${this.name} наелась`;
}
}

poop(): string {
if (this.feedCount >= 2) {
this.weight -= this.feedCount * 0.1;
return `${this.name} освободила свой пещевод на ${this.feedCount * 0.1} `;
this.feedCount = 0;
} else {
return `${this.name} еще не объелась`;
}
}

purring(): string {
this.petting += 1;
if (this.petting % 3 !== 0) {
return `${this.name} мурчит`
} else {
return `${this.name} делает кусь`
}
}

set age(age: number) {
this.aGe = age >= 0 && age < 21 ? age : this.aGe ?? 3;
}

get age(): number {
return this.aGe;
}
}
Loading