const useHint = (hintTime?: number): VoidFunction => {
const dispatch = useAppDispatch();
return () => {
dispatch({ type: setHintState.type, payload: { state: true } })
setTimeout(() => {
dispatch({ type: setHintState.type, payload: { state: false } })
}, hintTime && 300);
};
};
...
const Item: FC = () => {
const runHint = useHint(500);
return (
<>
<CopyButton
className='contacts-group-item-field__btn'
onClick={() => {
runHint(500);
navigator.clipboard.writeText('test')
}}
/>
</>
)
}
const result = JSON.parse(
'(1 (20 (400 5 60 (700) 108 (90)) 3))'
.replaceAll('(', '[')
.replaceAll(')', ']')
.replace(/(\d|\])(?=\s+\d|\s*\[)/g, '$&,'));
function getTree(str) {
const tokens = str.match(/\d+|[()]/g);
const stack = [];
let currentArr = null;
for(let i = 0; i < tokens.length; ++i) {
const token = tokens[i];
if (token === ')') {
if (!stack.length) {
return currentArr;
}
currentArr = stack.pop();
} else if (token === '(') {
const newArr = [];
if (currentArr) {
currentArr.push(newArr);
stack.push(currentArr);
}
currentArr = newArr;
} else {
if (currentArr) {
currentArr.push(parseInt(token));
}
}
}
return currentArr;
}
const result = getTree('(1 (20 (400 5 60 (700) 108 (90)) 3))');
для чего в первом типе используют K extends keyof Exist< O >
почему изначально проверка any[] extends A
type PickFromObject<O extends {}, K> = O extends O ? K extends K
? number extends K
? O[K & keyof O] | undefined
: `${number}` extends K
? O[K & keyof O] | undefined
: [never[], K] extends [O, number | `${number}`]
? O[K & keyof O] | undefined
: K extends keyof O ? O[K] : undefined
: never : never;
#include <iostream>
struct Node {
int value;
Node *next;
};
void RecursiveOutput( Node* item )
{
if ( item != 0 )
{
RecursiveOutput(item->next);
std::cout << item->value << std::endl;
}
}
void RecursiveInput( int n, int index = 1, Node* item = 0 )
{
if ( index <= n )
{
Node data;
std::cin >> data.value;
data.next = item;
RecursiveInput( n, index + 1, &data );
} else {
std::cout << "RecursiveOutput" << std::endl;
RecursiveOutput(item);
}
}
int DEPTH = 3;
int main()
{
std::cout << "input values: " << std::endl;
RecursiveInput(DEPTH);
std::cout << "end" << std::endl;
return 0;
}