Skip to content

Commit fc8650d

Browse files
Initial commit
0 parents  commit fc8650d

File tree

1,204 files changed

+406212
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,204 files changed

+406212
-0
lines changed

00-setup/snippets.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"Print to console": {
3+
"prefix": "cl",
4+
"scope": "javascript,typescript,javascriptreact",
5+
"body": ["console.log($1)"],
6+
"description": "console.log"
7+
},
8+
"reactComponent": {
9+
"prefix": "rfc",
10+
"scope": "javascript,typescript,javascriptreact",
11+
"body": [
12+
"function ${1:${TM_FILENAME_BASE}}() {",
13+
"\treturn (",
14+
"\t\t<div>",
15+
"\t\t\t$0",
16+
"\t\t</div>",
17+
"\t)",
18+
"}",
19+
"",
20+
"export default ${1:${TM_FILENAME_BASE}}",
21+
""
22+
],
23+
"description": "React component"
24+
},
25+
"reactStyledComponent": {
26+
"prefix": "rsc",
27+
"scope": "javascript,typescript,javascriptreact",
28+
"body": [
29+
"import styled from 'styled-components'",
30+
"",
31+
"const Styled${TM_FILENAME_BASE} = styled.$0``",
32+
"",
33+
"function ${TM_FILENAME_BASE}() {",
34+
"\treturn (",
35+
"\t\t<Styled${TM_FILENAME_BASE}>",
36+
"\t\t\t${TM_FILENAME_BASE}",
37+
"\t\t</Styled${TM_FILENAME_BASE}>",
38+
"\t)",
39+
"}",
40+
"",
41+
"export default ${TM_FILENAME_BASE}",
42+
""
43+
],
44+
"description": "React styled component"
45+
}
46+
}

01-pure-react/final/index.html

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Hello React!</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
12+
<script
13+
src="https://unpkg.com/react@18/umd/react.development.js"
14+
crossorigin
15+
></script>
16+
<script
17+
src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
18+
crossorigin
19+
></script>
20+
21+
<script>
22+
function App() {
23+
// const time = new Date().toLocaleTimeString();
24+
const [time, setTime] = React.useState(new Date().toLocaleTimeString());
25+
26+
React.useEffect(function () {
27+
setInterval(function () {
28+
setTime(new Date().toLocaleTimeString());
29+
}, 1000);
30+
}, []);
31+
32+
return React.createElement("header", null, `Hello React! It's ${time}`);
33+
}
34+
35+
const root = ReactDOM.createRoot(document.getElementById("root"));
36+
root.render(React.createElement(App));
37+
</script>
38+
</body>
39+
</html>

02-JS-review/final/script.js

+310
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
const data = [
2+
{
3+
id: 1,
4+
title: "The Lord of the Rings",
5+
publicationDate: "1954-07-29",
6+
author: "J. R. R. Tolkien",
7+
genres: [
8+
"fantasy",
9+
"high-fantasy",
10+
"adventure",
11+
"fiction",
12+
"novels",
13+
"literature",
14+
],
15+
hasMovieAdaptation: true,
16+
pages: 1216,
17+
translations: {
18+
spanish: "El señor de los anillos",
19+
chinese: "魔戒",
20+
french: "Le Seigneur des anneaux",
21+
},
22+
reviews: {
23+
goodreads: {
24+
rating: 4.52,
25+
ratingsCount: 630994,
26+
reviewsCount: 13417,
27+
},
28+
librarything: {
29+
rating: 4.53,
30+
ratingsCount: 47166,
31+
reviewsCount: 452,
32+
},
33+
},
34+
},
35+
{
36+
id: 2,
37+
title: "The Cyberiad",
38+
publicationDate: "1965-01-01",
39+
author: "Stanislaw Lem",
40+
genres: [
41+
"science fiction",
42+
"humor",
43+
"speculative fiction",
44+
"short stories",
45+
"fantasy",
46+
],
47+
hasMovieAdaptation: false,
48+
pages: 295,
49+
translations: {},
50+
reviews: {
51+
goodreads: {
52+
rating: 4.16,
53+
ratingsCount: 11663,
54+
reviewsCount: 812,
55+
},
56+
librarything: {
57+
rating: 4.13,
58+
ratingsCount: 2434,
59+
reviewsCount: 0,
60+
},
61+
},
62+
},
63+
{
64+
id: 3,
65+
title: "Dune",
66+
publicationDate: "1965-01-01",
67+
author: "Frank Herbert",
68+
genres: ["science fiction", "novel", "adventure"],
69+
hasMovieAdaptation: false,
70+
pages: 658,
71+
translations: {
72+
spanish: "",
73+
},
74+
reviews: {
75+
goodreads: {
76+
rating: 4.25,
77+
ratingsCount: 1142893,
78+
reviewsCount: 49701,
79+
},
80+
},
81+
},
82+
{
83+
id: 4,
84+
title: "Harry Potter and the Philosopher's Stone",
85+
publicationDate: "1997-06-26",
86+
author: "J. K. Rowling",
87+
genres: ["fantasy", "adventure"],
88+
hasMovieAdaptation: true,
89+
pages: 223,
90+
translations: {
91+
spanish: "Harry Potter y la piedra filosofal",
92+
korean: "해리 포터와 마법사의 돌",
93+
bengali: "হ্যারি পটার এন্ড দ্য ফিলোসফার্স স্টোন",
94+
portuguese: "Harry Potter e a Pedra Filosofal",
95+
},
96+
reviews: {
97+
goodreads: {
98+
rating: 4.47,
99+
ratingsCount: 8910059,
100+
reviewsCount: 140625,
101+
},
102+
librarything: {
103+
rating: 4.29,
104+
ratingsCount: 120941,
105+
reviewsCount: 1960,
106+
},
107+
},
108+
},
109+
{
110+
id: 5,
111+
title: "A Game of Thrones",
112+
publicationDate: "1996-08-01",
113+
author: "George R. R. Martin",
114+
genres: ["fantasy", "high-fantasy", "novel", "fantasy fiction"],
115+
hasMovieAdaptation: true,
116+
pages: 835,
117+
translations: {
118+
korean: "왕좌의 게임",
119+
polish: "Gra o tron",
120+
portuguese: "A Guerra dos Tronos",
121+
spanish: "Juego de tronos",
122+
},
123+
reviews: {
124+
goodreads: {
125+
rating: 4.44,
126+
ratingsCount: 2295233,
127+
reviewsCount: 59058,
128+
},
129+
librarything: {
130+
rating: 4.36,
131+
ratingsCount: 38358,
132+
reviewsCount: 1095,
133+
},
134+
},
135+
},
136+
];
137+
138+
function getBooks() {
139+
return data;
140+
}
141+
142+
function getBook(id) {
143+
return data.find((d) => d.id === id);
144+
}
145+
146+
// Destructuring
147+
148+
/*
149+
const book = getBook(3);
150+
book;
151+
152+
// const title = book.title;
153+
// const author = book.author;
154+
155+
const { title, author, pages, publicationDate, genres, hasMovieAdaptation } =
156+
book;
157+
158+
console.log(author, title, genres);
159+
160+
// const primaryGenre = genres[0];
161+
// const secondaryGenre = genres[1];
162+
163+
const [primaryGenre, secondaryGenre, ...otherGenres] = genres;
164+
console.log(primaryGenre, secondaryGenre, otherGenres);
165+
166+
const newGenres = ["epic fantasy", ...genres];
167+
newGenres;
168+
169+
const updatedBook = {
170+
...book,
171+
// Adding a new property
172+
moviePublicationDate: "2001-12-19",
173+
174+
// Overwriting an existing property
175+
pages: 1210,
176+
};
177+
updatedBook;
178+
179+
// function getYear(str) {
180+
// return str.split("-")[0];
181+
// }
182+
183+
const getYear = (str) => str.split("-")[0];
184+
console.log(getYear(publicationDate));
185+
186+
const summary = `${title}, a ${pages}-page long book, was written by ${author} and published in ${getYear(
187+
publicationDate
188+
)}. The book has ${hasMovieAdaptation ? "" : "not"} been adapted as a movie`;
189+
summary;
190+
191+
const pagesRange = pages > 1000 ? "over a thousand" : "less than 1000";
192+
pagesRange;
193+
console.log(`The book has ${pagesRange} pages`);
194+
195+
console.log(true && "Some string");
196+
console.log(false && "Some string");
197+
console.log(hasMovieAdaptation && "This book has a movie");
198+
199+
// falsy: 0, '', null, undefined
200+
console.log("jonas" && "Some string");
201+
console.log(0 && "Some string");
202+
203+
console.log(true || "Some string");
204+
console.log(false || "Some string");
205+
206+
console.log(book.translations.spanish);
207+
208+
const spanishTranslation = book.translations.spanish || "NOT TRANSLATED";
209+
spanishTranslation;
210+
211+
// console.log(book.reviews.librarything.reviewsCount);
212+
// const countWrong = book.reviews.librarything.reviewsCount || "no data";
213+
// countWrong;
214+
215+
// const count = book.reviews.librarything.reviewsCount ?? "no data";
216+
// count;
217+
218+
function getTotalReviewCount(book) {
219+
const goodreads = book.reviews?.goodreads?.reviewsCount;
220+
const librarything = book.reviews?.librarything?.reviewsCount ?? 0;
221+
librarything;
222+
return goodreads + librarything;
223+
}
224+
225+
console.log(getTotalReviewCount(book));
226+
*/
227+
228+
/*
229+
function getTotalReviewCount(book) {
230+
const goodreads = book.reviews?.goodreads?.reviewsCount;
231+
const librarything = book.reviews?.librarything?.reviewsCount ?? 0;
232+
librarything;
233+
return goodreads + librarything;
234+
}
235+
236+
const books = getBooks();
237+
books;
238+
239+
const x = [1, 2, 3, 4, 5].map((el) => el * 2);
240+
console.log(x);
241+
242+
const titles = books.map((book) => book.title);
243+
titles;
244+
245+
const essentialData = books.map((book) => ({
246+
title: book.title,
247+
author: book.author,
248+
reviewsCount: getTotalReviewCount(book),
249+
}));
250+
essentialData;
251+
252+
const longBooksWithMovie = books
253+
.filter((book) => book.pages > 500)
254+
.filter((book) => book.hasMovieAdaptation);
255+
longBooksWithMovie;
256+
257+
const adventureBooks = books
258+
.filter((books) => books.genres.includes("adventure"))
259+
.map((book) => book.title);
260+
adventureBooks;
261+
262+
const pagesAllBooks = books.reduce((sum, book) => sum + book.pages, 0);
263+
pagesAllBooks;
264+
265+
const arr = [3, 7, 1, 9, 6];
266+
const sorted = arr.slice().sort((a, b) => a - b);
267+
sorted;
268+
arr;
269+
270+
const sortedByPages = books.slice().sort((a, b) => a.pages - b.pages);
271+
sortedByPages;
272+
273+
// 1) Add book object to array
274+
const newBook = {
275+
id: 6,
276+
title: "Harry Potter and the Chamber of Secrets",
277+
author: "J. K. Rowling",
278+
};
279+
const booksAfterAdd = [...books, newBook];
280+
booksAfterAdd;
281+
282+
// 2) Delete book object from array
283+
const booksAfterDelete = booksAfterAdd.filter((book) => book.id !== 3);
284+
booksAfterDelete;
285+
286+
// 3) Update book object in the array
287+
const booksAfterUpdate = booksAfterDelete.map((book) =>
288+
book.id === 1 ? { ...book, pages: 1210 } : book
289+
);
290+
booksAfterUpdate;
291+
*/
292+
293+
// fetch("https://jsonplaceholder.typicode.com/todos")
294+
// .then((res) => res.json())
295+
// .then((data) => console.log(data));
296+
297+
// console.log("jonas");
298+
299+
async function getTodos() {
300+
const res = await fetch("https://jsonplaceholder.typicode.com/todos");
301+
const data = await res.json();
302+
console.log(data);
303+
304+
return data;
305+
}
306+
307+
const todos = getTodos();
308+
console.log(todos);
309+
310+
console.log("jonas");

0 commit comments

Comments
 (0)