Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pull request #15

Open
wants to merge 1 commit into
base: Lebedev_Egor_Andreevich
Choose a base branch
from
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
25 changes: 25 additions & 0 deletions codewars/Adding Big Numbers/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function add(a, b) {
let temp = 0
let mem = 0
if (Number(a) > Number(b)){
let c = a
a = b
b = c
}
while (a.length < b.length){
a = "0" + a
}
let ans = ""
for (let i = a.length-1; i >= 0; i--){
temp = Number(a[i]) + Number(b[i]) + mem
mem = 0
if (temp >= 10){
temp -= 10
mem = 1
}
ans = String(temp) + ans
}
if (mem == 1)
return String(mem) + ans
return ans
}
17 changes: 17 additions & 0 deletions codewars/Anagram difference/2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function anagramDifference(w1, w2){
let arr = []
let counter = 0
for (let i = 0; i < 26; i++)
arr.push(0)
for (let i = 0; i < w1.length; i++){
arr[w1[i].charCodeAt(0)-97]++
}
for (let i = 0; i < w2.length; i++){
let a = w2[i].charCodeAt(0)-97
if (arr[a] != 0){
arr[a]--
counter++
}
}
return w1.length + w2.length - counter*2
}
9 changes: 9 additions & 0 deletions codewars/Array Deep Count/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function deepCount(a){
let counter = 0
for (let i of a){
counter++
if (typeof i == "object")
counter = counter + deepCount(i)
}
return counter
}
22 changes: 22 additions & 0 deletions codewars/Build Tower/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export function towerBuilder (nFloors: number) {
let nStars = 1
let nSpaces = nFloors - 1
let arr: string[] = []
let str = ""
for (let i = 0; i < nFloors; i++){
for (let j = 0; j < nSpaces; j++){
str += " "
}
for (let j = 0; j < nStars; j++){
str += "*"
}
for (let j = 0; j < nSpaces; j++){
str += " "
}
arr.push(str)
str = ""
nStars += 2
nSpaces -= 1
}
return arr
}
20 changes: 20 additions & 0 deletions codewars/Convert string to camel case/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function toCamelCase(str){
let str2 = ""
let uppercase = false
let a = ""
for (let i = 0; i < str.length; i++){
if (uppercase){
a = (str[i]).toUpperCase()
uppercase = false
} else {
a = str[i]
}

if (a != "-" && a !="_"){
str2 += a
} else {
uppercase = true
}
}
return str2
}
19 changes: 19 additions & 0 deletions codewars/Duplicate Encoder/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export function duplicateEncode(word: string){
word = word.toLowerCase();
var ans = "";
var counter = 0;
for(var num = 0; num<word.length; num++) {
counter = 0;
for(var num2 = 0; num2<word.length; num2++){
if (word[num] == word[num2]){
counter++;
}
}
if (counter > 1){
ans += ")";
} else {
ans += "(";
}
}
return ans
}
12 changes: 12 additions & 0 deletions codewars/Find the missing letter/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function findMissingLetter(array:string[]):string
{
let ascii = array[0].charCodeAt(0)
for (var i = 1; i <= array.length; i++){
let ascii2 = array[i].charCodeAt(0)
if (ascii2-ascii != 1){
return String.fromCharCode(ascii+1)
}
ascii = ascii2
}
return ""
}
22 changes: 22 additions & 0 deletions codewars/Merge two arrays/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function mergeArrays(a, b) {
let array = [];
let max = 0;
if (a.length >= b.length){
max = a.length;
} else {
max = b.length;
}


for (var i = 0; i < max; i++ ){
if (i < a.length){
array.push(a[i]);
}
if (i < b.length){
array.push(b[i]);
}

}

return array
}
17 changes: 17 additions & 0 deletions codewars/Moving Zeros To The End/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function moveZeros(arr) {
let arr2 = []
let count = 0
for (let i = 0; i < arr.length; i++){
if (arr[i] === 0) {
count++
} else {
arr2.push(arr[i])
}
}
for (let i = 0; i < count; i++){
arr2.push(0)
}
return arr2
}

console.log(moveZeros([false,1,0,1,2,0,1,3,"a"]))
14 changes: 14 additions & 0 deletions codewars/Product of consecutive Fib numbers/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export function productFib (prod:number){
let a = 1
while (fib(a) * fib(a-1) <= prod){
if (fib(a) * fib(a-1) == prod)
return [fib(a-1), fib(a), true]
a++
}
return [fib(a-1), fib(a), false]
}

export function fib (a: number): number{
let fiveroot = Math.sqrt(5)
return Math.round((((1 + fiveroot)/2)**a-((1 - fiveroot)/2)**a)/fiveroot)
}
15 changes: 15 additions & 0 deletions codewars/Simple Pig Latin/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function pigIt (a : string) {
let ans = ""
let arr = a.split(" ")
for (let i of arr){
if (i != ""){
if (i == "!" || i == "." || i == "," || i == "?"){
ans += i + " "
} else
ans += i.substring(1, i.length) + i[0] + "ay ";
} else
ans += " "
}

return ans.substring(0, ans.length-1)
}
20 changes: 20 additions & 0 deletions codewars/Snail/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function snail (arr) {
let iteration = 0
let n = arr[0].length
let ans = []
for (let iteration = 0; iteration < Math.round(n/2); iteration++){
for (let i = 0+iteration; i<n-iteration; i++){
ans.push(arr[iteration][i])
}
for (let i = 1+iteration; i<n-1-iteration; i++){
ans.push(arr[i][n-1-iteration])
}
for (let i = n-1-iteration; i > iteration; i-- ){
ans.push(arr[n-1-iteration][i])
}
for(let i = n-1-iteration; i >= iteration+1; i--){
ans.push(arr[i][iteration])
}
}
return ans
}
12 changes: 12 additions & 0 deletions codewars/Sum of Digits - Digital Root/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const digitalRoot = (n:number):number => {
let num = String(n);
let sum = 0;
while (num.length > 1){
for (let i = 0; i < num.length; i++){
sum += Number(num[i]);
}
num = String(sum)
sum = 0
}
return Number(num)
};
31 changes: 31 additions & 0 deletions codewars/Tic-Tac-Toe Checker/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function isSolved(board) {
let arr = []
var isnull = false
for (let i of board){
for (let j of i){
if (j == 0){
isnull = true
}
arr.push(j)
}
}
for (let i = 0; i < 9; i += 3){
let temp = arr[i]
if (temp== arr[i+1] && temp == arr[i+2] && temp != 0 && i < 7){
return temp
} else if (i < 3) {
if (temp== arr[i+3] && temp == arr[i+6] && temp != 0){
return temp
}
}
}
let temp = arr[4]
if ((temp == arr[0] && temp == arr[8] && temp != 0) || (temp == arr[2] && temp == arr[6] && temp != 0)){
return temp
}
if (isnull){
return -1
} else {
return 0
}
}
52 changes: 52 additions & 0 deletions rpgsaga/saga/Class/dish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { service } from "./service";

export class Dish extends service {

public name: string;
public price: number;
private ingredients: string[] = [];

constructor(name: string, price: number, public mass?:number){
super(name, price)
this.mass = mass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

значит я могу отрицательные значения mass выставить?

}

getInfo(): string{
return (`${this.name}: Price: ${this.price}$, Mass: ${this.mass}g, Ingredients: ${this.ingredients}. `)
}

addIngredient(newIngredient: string){
this.ingredients.push(newIngredient)
}

addIngredients(newIngredients: string[]){
for (let i of newIngredients){
this.ingredients.push(i)
}
}

deleteIngredient(ingredient: string | number){
if (typeof ingredient == "string"){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот это может вести к 2 методам DeleteByID и DeleteByName

if (ingredient == "all")
this.ingredients = []
else {
for (let i in this.ingredients){
if (this.ingredients[i] == ingredient){
this.ingredients.splice(Number(i), 1)
break
}
}
}
}
if (typeof ingredient == "number")
this.ingredients.splice(ingredient,1)
}

pay(money: number): number{
if (super.pay(money) != money - this.price){
console.log(`${this.name} was paid`);
return money
}
}
}

22 changes: 22 additions & 0 deletions rpgsaga/saga/Class/entertainment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { service } from "./service";

export class Entertainment extends service{

constructor(name: string, price: number, public time?: number){
super(name, price);
this.time = time;
}
pay(money: number): number{
if (super.pay(money) == money - this.price){
console.log(`${this.time} mins of ${this.name} was paid`);
return money
}

}

getInfo(): string{
return (`${this.name}: Price: ${this.price}$, Time: ${this.time} `)
}


}
13 changes: 13 additions & 0 deletions rpgsaga/saga/Class/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Dish } from "./dish";


let pizza = new Dish("Margarita", 5, 500);
pizza.addIngredients(["dough", "sauce", "cheese", "tomato"])
console.log(pizza.getInfo());
pizza.addIngredient("chili");
pizza.addIngredient("tomato");
console.log(pizza.getInfo());
pizza.deleteIngredient("tomato");
console.log(pizza.getInfo());
pizza.deleteIngredient(3);
console.log(pizza.getInfo());
19 changes: 19 additions & 0 deletions rpgsaga/saga/Class/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export abstract class service{
public name: string;
public price: number;
constructor(name: string, price: number){
this.name = name;
this.price = price;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я могу создать сервис с отрицательной ценой ....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

добавляйте set и get и используйте их в конструкторе

}
public abstract getInfo();

public pay(money: number){
if (money >= this.price){
return money -= this.price
} else {
console.log(`Not enough money`)
return money
}

}
}
Loading