├── README.md
├── algorithms
└── js.md
├── cheatsheet
└── bash.md
├── interview
├── css.md
├── general.md
├── html.md
└── js.md
└── projects
└── weather
├── index.html
├── readme.md
├── scripts.js
└── styles.css
/README.md:
--------------------------------------------------------------------------------
1 | # cheat
2 | :memo: cheatsheet for frontend, coding, and interview questions
3 |
--------------------------------------------------------------------------------
/algorithms/js.md:
--------------------------------------------------------------------------------
1 | # JS Algorithms
2 |
3 |
4 | ### String
5 |
6 | Reverse a string:
7 | ```js
8 | function reverse(str) {
9 | return str.split("").reverse().join("");
10 | }
11 | ```
12 |
13 | Find longest word:
14 | ```js
15 | function findLongestWord(str) {
16 | var words = str.split(" ");
17 | str = words.sort(function(a, b) {
18 | return b.length - a.length;
19 | })[0];
20 | return str;
21 | }
22 | ```
23 |
24 | ### Numbers
25 |
26 | Factorialize:
27 | ```js
28 | function factorialize(num) {
29 | if(num === 0) return 1;
30 | return num * factorialize(num-1);
31 | }
32 | ```
33 |
34 | FizzBuzz:
35 | ```js
36 | for(var i = 0; i <= 100; i++) {
37 | var f = i % 3 == 0, b = i % 5 == 0, fb = f && b
38 | console.log(f ? "Fizz" : b ? "Buzz" : fb ? "FizzBuzz" : i)
39 | }
40 | ```
41 |
42 | ### Sorting
43 |
44 | Bubble Sort:
45 | ```js
46 | function bub(arr) {
47 | for (var j = 0; j < arr.length; j++) {
48 | for (var i = 0; i < (arr.length - j); i++) {
49 | if (arr[i] > arr[i + 1]) {
50 | var a = arr[i]
51 | var b = arr[i + 1]
52 | arr[i] = b
53 | arr[i + 1] = a
54 | }
55 | }
56 | }
57 | return arr;
58 | }
59 | ```
60 |
61 | Quicksort:
62 | ```js
63 | var quick = function(arr, condition) {
64 | if(arr.length < 2) {
65 | return arr;
66 | };
67 | var pivot = arr[Math.floor(Math.random()*arr.length)];
68 | var left = [];
69 | var equal = [];
70 | var right = [];
71 | for(var i = 0; i < arr.length; i++) {
72 | var item = arr[i];
73 | var sortable = condition(item, pivot);
74 | if(item === pivot) {
75 | equal.push(item)
76 | } else if(sortable) {
77 | left.push(item);
78 | } else {
79 | right.push(item);
80 | }
81 | }
82 | return quick(left, condition).concat(equal, quick(right, condition));
83 | }
84 | ```
85 |
86 | Native JS Sort:
87 | ```js
88 | var arr = [454, 664,224, 675, 4]
89 | arr.sort(function(a, b) {
90 | return a - b;
91 | });
92 | ```
93 |
94 | ### Search
95 |
96 | Binary Search
97 | ```js
98 | var binarySearch = function(query, arr) {
99 | var start = 0;
100 | var end = arr.length - 1;
101 | while(start <= end) {
102 | var index = Math.round((start + end) / 2);
103 | var item = arr[index];
104 | if(query === item) {
105 | return index;
106 | } else if(query > item) {
107 | start = index + 1;
108 | } else {
109 | end = index - 1;
110 | }
111 | }
112 | return null;
113 | }
114 | binarySearch(3, [1, 2, 3, 4, 5]);
115 | // => 2
116 | ```
117 |
118 | ### Other
119 |
120 | Check if "robot" has gone a circle, given a list of directions:
121 |
122 | ```js
123 | function circle(directions) {
124 | directions = directions.split("");
125 | var x = 0,
126 | y = 0,
127 | ox = 0,
128 | oy = 0,
129 | it = 0,
130 | forv = "F";
131 | document.write("DIRECTIONS: " + directions + "
")
132 | for (var j = 0; j < 4; j++) {
133 | for (var i = 0; i < directions.length; i++) {
134 | var d = directions[i];
135 | switch (d) {
136 | case "F":
137 | if (forv === "F") {
138 | y++;
139 | forv = "F";
140 | } else if (forv === "L") {
141 | x--;
142 | forv = "L";
143 | } else if (forv === "R") {
144 | x++;
145 | forv = "R";
146 | } else if (forv = "B") {
147 | y--;
148 | forv = "B";
149 | }
150 | it++;
151 | document.write("X: " + x, " Y: " + y + "
");
152 | if (it % 4 === 0) {
153 | if (x === ox && y === oy) {
154 | document.write("CIRCLE DETECTED! CIRCUMFERENCE: " + it + "
");
155 | ox = x;
156 | oy = y;
157 | }
158 | }
159 | break;
160 | case "L":
161 | if (forv === "F") {
162 | x--;
163 | forv = "L"
164 | } else if (forv === "L") {
165 | y--;
166 | forv = "B";
167 | } else if (forv === "R") {
168 | y++;
169 | forv = "F";
170 | } else if (forv === "B") {
171 | x++;
172 | forv = "R";
173 | }
174 | it++;
175 | document.write("X: " + x, " Y: " + y + "
");
176 | if (it % 4 === 0) {
177 | if (x === ox && y === oy) {
178 | document.write("CIRCLE DETECTED! CIRCUMFERENCE: " + it + "
");
179 | ox = x;
180 | oy = y;
181 | }
182 | }
183 | break;
184 |
185 | case "R":
186 | if (forv === "F") {
187 | x++;
188 | forv = "R"
189 | } else if (forv === "L") {
190 | y++;
191 | forv = "F";
192 | } else if (forv === "R") {
193 | y--;
194 | forv = "B";
195 | } else if (forv === "B") {
196 | x--;
197 | forv = "L";
198 | }
199 | it++;
200 | document.write("X: " + x, " Y: " + y + "
");
201 | if (it % 4 === 0) {
202 | if (x === ox && y === oy) {
203 | document.write("CIRCLE DETECTED! CIRCUMFERENCE: " + it + "
");
204 | ox = x;
205 | oy = y;
206 | }
207 | }
208 | break;
209 |
210 | default:
211 | document.write("Command Error");
212 | }
213 | }
214 | }
215 | }
216 | ```
217 |
--------------------------------------------------------------------------------
/cheatsheet/bash.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/interview/css.md:
--------------------------------------------------------------------------------
1 | # CSS Interview Questions
2 |
3 | * What does CSS Stand for?
4 | * What is CSS used for?
5 | * What is the difference between classes and id's?
6 | * Are you familiar with Animations?
7 | * What is the difference between animations and transitions?
8 | * What is responsiveness?
9 | * What is flexbox?
10 | * Have you used any CSS frameworks? Which one?
11 |
--------------------------------------------------------------------------------
/interview/general.md:
--------------------------------------------------------------------------------
1 | # General Interview Questions
2 |
3 | * Why are you interested in coding?
4 | * What is the newest thing you have learned?
5 | * What is a challenge that you came across recently?
6 | * How did you figure it out?
7 | * What is your development environment?
8 | * How do you control version?
9 | * What do you want to learn this year?
10 |
--------------------------------------------------------------------------------
/interview/html.md:
--------------------------------------------------------------------------------
1 | # HTML Interview Questions
2 |
3 | * What does HTML stand for?
4 | * What does `doctype` do?
5 | * What is the key difference between HTML and XML?
6 | * What are `meta` tags?
7 | * How do you use `data-` attributes?
8 | * What is the difference between `cookies`, `sessionStorage`, and `localStorage`?
9 | * Where do you link to CSS and JS? Why?
10 | * Have you used HTML templating?
11 |
--------------------------------------------------------------------------------
/interview/js.md:
--------------------------------------------------------------------------------
1 | # JS Interview Questions
2 |
3 | * What is JS used for?
4 | * What is an event?
5 | * What is an object?
6 | * How do you use `this`?
7 | * What does a semicolon indicate?
8 | * What is a loop? How are they used?
9 | * What is an array?
10 |
--------------------------------------------------------------------------------
/projects/weather/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |