Skip to content

Commit

Permalink
fixed pluralize
Browse files Browse the repository at this point in the history
  • Loading branch information
FreshSymbol committed Sep 12, 2024
1 parent 9738655 commit b77ea3f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import './styles.css';
import { pluralize } from './utils';

/**
* Приложение
Expand Down Expand Up @@ -27,7 +28,8 @@ function App({ store }) {
>
<div className="Item-code">{item.code}</div>
<div className="Item-title">
{item.title} {item.count > 0 ? `| Выделяли ${item.count} раз` : ''}
{item.title}
{item.count > 0 ? `| Выделяли ${item.count} ${pluralize(item.count)}` : ''}
</div>
<div className="Item-actions">
<button onClick={() => store.deleteItem(item.code)}>Удалить</button>
Expand Down
15 changes: 7 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import React from 'react';
import { createRoot } from 'react-dom/client';
import { getGenerateCode } from './utils.js';
import App from './app.js';
import Store from './store.js';

const store = new Store({
list: [
{ code: getGenerateCode(), title: 'Название элемента', count: 0 },
{ code: getGenerateCode(), title: 'Некий объект', count: 0 },
{ code: getGenerateCode(), title: 'Заголовок', count: 0 },
{ code: getGenerateCode(), title: 'Очень длинное название элемента из семи слов', count: 0 },
{ code: getGenerateCode(), title: 'Запись', count: 0 },
{ code: getGenerateCode(), title: 'Шестая запись', count: 0 },
{ code: getGenerateCode(), title: 'Седьмая запись', count: 0 },
{ code: 1, title: 'Название элемента', count: 0 },
{ code: 2, title: 'Некий объект', count: 0 },
{ code: 3, title: 'Заголовок', count: 0 },
{ code: 4, title: 'Очень длинное название элемента из семи слов', count: 0 },
{ code: 5, title: 'Запись', count: 0 },
{ code: 6, title: 'Шестая запись', count: 0 },
{ code: 7, title: 'Седьмая запись', count: 0 },
],
});

Expand Down
10 changes: 9 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ export function createElement(name, props = {}, ...children) {

// Генерация уникального кода
function generateCode() {
let code = 0;
let code = 7;
return function () {
return ++code;
};
}

export const getGenerateCode = generateCode();

//Плюрализация
export function pluralize(number) {
const forms = ['раз', 'раза', 'раз'];
if (number % 10 === 1 && number % 100 !== 11) return forms[0];
else if ([2, 3, 4].includes(number % 10) && ![12, 13, 14].includes(number % 100)) return forms[1];
else return forms[2];
}

0 comments on commit b77ea3f

Please sign in to comment.