generated from skills/copilot-codespaces-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (39 loc) · 1.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
Create a basic markdown editor in Next.js with the following features:
- Use react hooks
- Create a state for markdown with the default text "type markdown here"
- A text area where users can write markdown
- Show a live preview of the markdown text as I type
- Support for basic markdown syntax like headers, bold, and italics
- Use React markdown npm package
- The markdown text and resulting HTML should be saved in the component's state and updated in real-time
*/
function MarkdownEditor() {
const [markdown, setMarkdown] = useState('type markdown here');
const handleMarkdownChange = (event) => {
setMarkdown(event.target.value);
};
return (
<div>
<textarea value={markdown} onChange={handleMarkdownChange} />
<ReactMarkdown>{markdown}</ReactMarkdown>
</div>
);
}
export default MarkdownEditor;
function capitalizeFirstLetter(sentence) {
return sentence.charAt(0).toUpperCase() + sentence.slice(1);
}
const reversedSentence = capitalizeFirstLetter(markdown.split(' ').reverse().join(' '));
console.log(reversedSentence);
const data = [
[
{ name: 'John', age: 25 },
{ name: 'Jane', age: 30 }
],
[
{ name: 'Bob', age: 40 }
]
];
const names = data.flatMap(group => group.map(person => person.name));
console.log(names);