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

Month 12/step 1 #1

Merged
merged 33 commits into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a626010
add string component
LexorV May 31, 2022
0768fab
add style string
LexorV May 31, 2022
7c00625
logics without color
LexorV Jun 3, 2022
bf2021c
add color logics
LexorV Jun 3, 2022
6c20074
fix logics string
LexorV Jun 3, 2022
2b9e5d9
add fibonacci and fix string
LexorV Jun 3, 2022
4318a26
fibonacci logics add
LexorV Jun 4, 2022
68bd4ca
layout sorting
LexorV Jun 5, 2022
928643c
add babelSort
LexorV Jun 6, 2022
00f646f
add slectionSort logics
LexorV Jun 7, 2022
a4ca80b
sorting-page full
LexorV Jun 7, 2022
7242dff
stack layout add
LexorV Jun 7, 2022
6d922b5
stack-page full
LexorV Jun 8, 2022
4fb1cdb
fix clear stack-page
LexorV Jun 8, 2022
172f2a2
layout queue-page add
LexorV Jun 8, 2022
3ab10bf
add logics queue
LexorV Jun 9, 2022
4cd32f7
fix button
LexorV Jun 9, 2022
a90abaa
layout add
LexorV Jun 10, 2022
2e525a2
logics add
LexorV Jun 10, 2022
71ce9f3
animation head and tail
LexorV Jun 11, 2022
3b065e2
add anim dell head and dell tail
LexorV Jun 11, 2022
118851d
animation add addByIndex
LexorV Jun 12, 2022
06008b0
add dell index anim and state button
LexorV Jun 12, 2022
c1a83e0
ts linkedList part_1
LexorV Jun 12, 2022
5a97c67
TS linkedList part_2
LexorV Jun 13, 2022
5011c51
min-fix global
LexorV Jun 13, 2022
c374761
fix stringSort
LexorV Jun 13, 2022
bb33655
fibonacci fix
LexorV Jun 13, 2022
3504932
sorting page fix
LexorV Jun 13, 2022
397eb61
fix stack
LexorV Jun 13, 2022
e940a62
fix queue
LexorV Jun 14, 2022
28b2632
fix list-page
LexorV Jun 15, 2022
86aa14a
mini fix fibonacci
LexorV Jun 15, 2022
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
10,884 changes: 10,884 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/components/fibonacci-page/fibonacci-page.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.box_input {
display:flex;
width:522px;
gap:12px;
}
.box_main {
display:flex;
flex-direction: column;
align-items: center;
}
.lists_circle {
list-style-type: none;
display: flex;
gap: 16px;
flex-wrap:wrap;
max-width:944px;
}
72 changes: 69 additions & 3 deletions src/components/fibonacci-page/fibonacci-page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,76 @@
import React from "react";
import React, { useState, ChangeEvent, SyntheticEvent} from "react";
import { SolutionLayout } from "../ui/solution-layout/solution-layout";

import { Circle } from '../ui/circle/circle';
import { Input } from "../ui/input/input";
import { Button } from "../ui/button/button";
import { uid } from '../../helper/helper';
import fibonacciStyle from './fibonacci-page.module.css'
export const FibonacciPage: React.FC = () => {
const [numberInput, setNumberInput] = useState<number>(0);
const [started, setStarted] = useState<boolean>(false);
const [indexfib, setIndexfib] = useState<number | null>(null)
const [arrNumber, setArrNumber] = useState<number[]>([]);
const fiboAlgo = async (
n: number
) => {
let arr: number[] = [];
for (let i = 0; i < n + 1; i++) {
await new Promise<void>((res) => {
setTimeout(() => {
res()
}, 500)
})
Copy link

@kyzinatra kyzinatra Jun 12, 2022

Choose a reason for hiding this comment

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

Надо исрпавить: По аналогии стоит вынести сам алгоритм генерации чисел фибоначи в отдельный файл, а тут просто выводить результат его работы.

По аналогии в каждом компоненте алгоритов

if(arr.length < 1) {
arr.push(0)
setIndexfib(i)
setArrNumber(arr)
}
else if(arr.length < 2) {
arr.push(1)
setIndexfib(i)
setArrNumber(arr)
}
else {
arr.push(arr[i - 2] + arr[i - 1])
setIndexfib(i)
setArrNumber(arr)
}
}
}
const startAlgo = async () => {
setStarted(true)
await fiboAlgo(numberInput)
setStarted(false)
}
const onFormChange = (e: ChangeEvent<HTMLInputElement>) => {
setNumberInput(parseInt(e.target.value));
}
const onChangeForm = (e: SyntheticEvent) => {
e.preventDefault();
startAlgo()
}
return (
<SolutionLayout title="Последовательность Фибоначчи">

<div className={fibonacciStyle.box_main}>
<form onSubmit={onChangeForm} className={fibonacciStyle.box_input}>
<Input
type="number"
isLimitText={true}
max={19}
value={numberInput}

Choose a reason for hiding this comment

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

Можно лучше: При числах > 19 стоит блокировать пользователю кнопку запуска

onChange={onFormChange} />
<Button isLoader={started} type="submit" text='Расчитать' />
</form>
<ul className={fibonacciStyle.lists_circle}>
{arrNumber.length >= 1 && (arrNumber.map((list) => {
return (
<li key={uid()} >
<Circle letter={list} />
</li>)
}))}
</ul>
</div>

</SolutionLayout>
);
};
257 changes: 257 additions & 0 deletions src/components/list-page/linkedList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
import {ReactElement} from "react";

export class Node<T> {
value: T
next: Node<T> | null
constructor(value: T, next?: Node<T> | null) {
this.value = value;
this.next = (next === undefined ? null : next);
}
}
//Пока не до конца типизировано. В работе.
import { ElementStates } from '../../types/element-states';
interface ILinkedList<T> {

Choose a reason for hiding this comment

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

Надо исправить: Все импорты должы располагаться в начале файла. Из-за этого могут вылазить ошибки компиляции

append: (element: T) => void;
getSize: () => number;
toArray: () => void;
prepend: (element: T) => void
addByIndex: (element:T, index: number, al:ReactElement) => void;
deleteByIndex: (
index:number,
cicleCallback: (text:string | number) => ReactElement) => void;
deleteHead: () => void;
deleteTail: () => void;
}
export class LinkedList<T> implements ILinkedList<T> {
private head: any;
private size: number;
private tail: Node<T> | null;;
arr: any;
setArr: any;
setChange: any;
setStarted: any;
constructor(arr: any,
setArr: any,
setChange: any,
setStarted: any) {
this.arr = arr;

Choose a reason for hiding this comment

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

Надо исправить: не стоит использовать значения any. Стоит либо их строго типизировать, либо использовать дженерики

this.head = null;
this.size = 0;
this.tail = null;
this.setArr = setArr;
this.setChange = setChange;
this.setStarted = setStarted;
}

addByIndex = async (element: T, index: number, al: ReactElement) => {
if (index < 0 || index > this.size) {
console.log('Enter a valid index');
return;
} else {
const node = new Node<any>(element);
if (index === 0) {
this.setChange(true)
this.head.value.head = al
await new Promise<void>((res) => {
setTimeout(() => {
res()
}, 1000)
});
this.setChange(false)
node.next = this.head;
node.value.head = 'head'
this.head.value.head = ''
this.head = node;
this.setArr(this.toArray());
await new Promise<void>((res) => {
setTimeout(() => {
res()
}, 1000)
});
node.value.style = ElementStates.Default
} else {
let curr = this.head;
let currIndex = 0;
let prev = null
curr.value.style = ElementStates.Changing
curr.value.head = al;
while (currIndex < index) {
this.setChange(true)
currIndex++
await new Promise<void>((res) => {
setTimeout(() => {
res()
}, 1000)
});
prev = curr
prev.value.style = ElementStates.Changing;
currIndex === 1 ? prev.value.head = "head" : prev.value.head = '';
curr = curr.next;
curr.value.head = al;
this.setChange(false)
if (currIndex == index) {
prev.value.head === "head" ? prev.value.head = 'head' : prev.value.head = '';
curr.value.head = '';
this.defaultColor();

}
else {
curr.value.style = ElementStates.Changing
curr.value.head = al;
}
}
await new Promise<void>((res) => {
setTimeout(() => {
res()
}, 1000)
});
node.next = curr;
prev.next = node;
this.setArr(this.toArray())
await new Promise<void>((res) => {
setTimeout(() => {
res()
}, 1000)
});
prev.next.value.style = ElementStates.Default
}
this.size++;
}
}
defaultColor() {
let currentNode = this.head;
while (currentNode) {
currentNode.value.style = ElementStates.Default
currentNode = currentNode.next;
}
}
deleteByIndex = async (index: number, cicleCallback: (text:string | number) => ReactElement) => {
if (index >= this.size) {
throw new Error("error size");
}
if (index === 0) {
return this.deleteHead();
}
let prev = null;
let curr = this.head;
let currentIndex = 0;
curr.value.style = ElementStates.Changing
while (currentIndex < index) {
this.setChange(true)
currentIndex++
await new Promise<void>((res) => {
setTimeout(() => {
res()
}, 1000)
});
prev = curr;
// prev.value.style = ElementStates.Changing;
curr = curr.next;
//this.setArr(this.toArray());
this.setChange(false)

if (currentIndex == index) {
this.setChange(true)
let text = curr.value.text
curr.value.style = ElementStates.Changing;
this.setArr(this.toArray());
await new Promise<void>((res) => {
setTimeout(() => {
res()
}, 1000)
});
curr.value.text = '';
curr.value.style = ElementStates.Default;
curr.value.tail = cicleCallback(text);
this.setChange(false);
// prev.value.tail = ''
// curr.value.tail = '';

}
else {
curr.value.style = ElementStates.Changing


}

}
await new Promise<void>((res) => {
setTimeout(() => {
res()
}, 1000)
});
prev.value.tail = 'tail';
prev.next = curr.next;
this.defaultColor();
this.setArr(this.toArray());

this.size--;
return this;
}
deleteHead() {
if (!this.head) return null;

if (this.head.next) {
this.head = this.head.next;
} else {
this.head = null;
this.tail = null;
}

return this;
}
deleteTail() {
const deletedTail = this.tail;
if (this.head === this.tail) {
this.head = null;
this.tail = null;
return deletedTail;
}
let current = this.head;
while (current?.next) {
if (!current.next.next) {
current.next = null;
} else {
current = current.next;
}
}

this.tail = current;
return this;
}

prepend(element: T) {
const node = new Node(element);
if (!this.head || !this.tail) {
this.head = node;
this.tail = node;
return this;
}
this.tail.next = node;
this.tail = node;
this.size++
return this
}
append = async (element: any) => {
const node = new Node(element, this.head);
this.head = node;
if (!this.tail) {
this.tail = node
}
this.size++
return this
}
toArray = () => {
const nodes = [];
let currentNode = this.head;
while (currentNode) {
nodes.push(currentNode)
currentNode = currentNode.next;
}
return nodes;
}

getSize() {
return this.size;
}
}
28 changes: 28 additions & 0 deletions src/components/list-page/list-page.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.box_input {
display:flex;
width:952px;
gap:12px;
}
.box_main {
display:flex;
flex-direction: column;
align-items: center;
}
.lists_circle {
list-style-type: none;
display: flex;
gap: 25px;
}
.input_field_size {
width:204px;
}
.button_size {
width:175px;
}
.list {
display:flex;
align-items: center;
gap: 25px;


}
Loading