-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1715 lines (1180 loc) · 82.9 KB
/
index.html
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset="utf-8">
<title>Mason's blog</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta property="og:type" content="website">
<meta property="og:title" content="Mason's blog">
<meta property="og:url" content="https://minsooshin.github.io/index.html">
<meta property="og:site_name" content="Mason's blog">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Mason's blog">
<link rel="icon" href="/css/images/logo.png" />
<link rel="stylesheet" href="/libs/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="/libs/open-sans/styles.css">
<link rel="stylesheet" href="/libs/source-code-pro/styles.css">
<link rel="stylesheet" href="/css/style.css">
<script src="/libs/jquery/2.1.3/jquery.min.js"></script>
<link rel="stylesheet" href="/libs/lightgallery/css/lightgallery.min.css">
<link rel="stylesheet" href="/libs/justified-gallery/justifiedGallery.min.css">
</head>
<body>
<div id="container">
<header id="header">
<div id="header-main" class="header-inner">
<div class="outer">
<a href="/" id="logo">
<i class="logo"></i>
<span class="site-title">Mason's blog</span>
</a>
<nav id="main-nav">
<a class="main-nav-link" href="/.">Home</a>
<a class="main-nav-link" href="/archives">Archives</a>
<a class="main-nav-link" href="/categories">Categories</a>
</nav>
<nav id="sub-nav">
<div class="profile" id="profile-nav">
<a id="profile-anchor" href="javascript:;">
<img class="avatar" src="/css/images/avatar.png" />
<i class="fa fa-caret-down"></i>
</a>
</div>
</nav>
<div id="search-form-wrap">
<form class="search-form">
<input type="text" class="ins-search-input search-form-input" placeholder="Search" />
<button type="submit" class="search-form-submit"></button>
</form>
<div class="ins-search">
<div class="ins-search-mask"></div>
<div class="ins-search-container">
<div class="ins-input-wrapper">
<input type="text" class="ins-search-input" placeholder="Type something..." />
<span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
</div>
<div class="ins-section-wrapper">
<div class="ins-section-container"></div>
</div>
</div>
</div>
<script>
(function (window) {
var INSIGHT_CONFIG = {
TRANSLATION: {
POSTS: 'Posts',
PAGES: 'Pages',
CATEGORIES: 'Categories',
TAGS: 'Tags',
UNTITLED: '(Untitled)',
},
ROOT_URL: '/',
CONTENT_URL: '/content.json',
};
window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>
</div>
</div>
</div>
<div id="main-nav-mobile" class="header-sub header-inner">
<table class="menu outer">
<tr>
<td><a class="main-nav-link" href="/.">Home</a></td>
<td><a class="main-nav-link" href="/archives">Archives</a></td>
<td><a class="main-nav-link" href="/categories">Categories</a></td>
<td>
<div class="search-form">
<input type="text" class="ins-search-input search-form-input" placeholder="Search" />
</div>
</td>
</tr>
</table>
</div>
</header>
<div class="outer">
<aside id="profile">
<div class="inner profile-inner">
<div class="base-info profile-block">
<img id="avatar" src="/css/images/avatar.png" />
<h2 id="name">Mason Shin</h2>
<h3 id="title">Front-End Player</h3>
<span id="location"><i class="fa fa-map-marker"></i>San Francisco Bay Area</span>
<a id="follow" target="_blank" href="https://github.com/minsooshin/">FOLLOW</a>
</div>
<div class="article-info profile-block">
<div class="article-info-block">
10
<span>posts</span>
</div>
<div class="article-info-block">
14
<span>tags</span>
</div>
</div>
<div class="profile-block social-links">
<table>
<tr>
<td>
<a href="https://github.com/minsooshin/" target="_blank" title="github" class=tooltip>
<i class="fa fa-github"></i>
</a>
</td>
<td>
<a href="https://www.facebook.com/mason.shin" target="_blank" title="facebook" class=tooltip>
<i class="fa fa-facebook"></i>
</a>
</td>
<td>
<a href="https://www.linkedin.com/in/masonshin/" target="_blank" title="linkedin" class=tooltip>
<i class="fa fa-linkedin"></i>
</a>
</td>
</tr>
</table>
</div>
</div>
</aside>
<section id="main">
<article id="post-Code-Convention-Tooling-for-Better-Collaboratation" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-inner">
<a href="/2017/05/18/Code-Convention-Tooling-for-Better-Collaboratation/" itemprop="url">
<img src="/images/code_convention_banner.png" class="article-banner" />
</a>
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2017/05/18/Code-Convention-Tooling-for-Better-Collaboratation/">Code Convention Tooling for Better Collaboratation</a>
</h1>
<div class="article-meta">
<div class="article-date">
<i class="fa fa-calendar"></i>
<a href="/2017/05/18/Code-Convention-Tooling-for-Better-Collaboratation/">
<time datetime="2017-05-18T20:14:53.000Z" itemprop="datePublished">2017-05-18</time>
</a>
</div>
<div class="article-category">
<i class="fa fa-folder"></i>
<a class="article-category-link" href="/categories/tutorial/">tutorial</a>
</div>
<div class="article-tag">
<i class="fa fa-tag"></i>
<a class="tag-link" href="/tags/Eslint/">Eslint</a>, <a class="tag-link" href="/tags/JavaScript/">JavaScript</a>, <a class="tag-link" href="/tags/React/">React</a>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<p><p>If you have worked at any size of company before or now, you have had the difficulty about inconsistent code styles to work with. I have worked at a company which has front-end code based on Rails platform. At that time, it was really diffult to have code convention tools for front-end. So, whenever someone has pull request to get review, other engineers need to make a comment on each code convention issue. Obviously, there were some struggling about those comments since it doesn’t affect on the performance at all, it just style preference, and it cannot be agreed from all of the engineering team sometimes. In that situation, some engineers ignore the comment and merge their pull request without applying it, and it can be a critical communication issue.</p>
<p>Fortunately, the architect team decided to move on to node.js platform for front-end, and we could introduce code convention tools for entire JavaScript code. Then, integrated with CI tool, jenkins, to run lint testing whenever there is new pull request created.</p>
<p>I would like to share how to set up the linter tool for JavaScript code base application, and how to integrate with Travis CI for your personal projects on Github.</p></p>
<p class="article-more-link">
<a href="/2017/05/18/Code-Convention-Tooling-for-Better-Collaboratation/#more">Read More</a>
</p>
</div>
<footer class="article-footer">
<div class="share-container">
</div>
<a data-url="https://minsooshin.github.io/2017/05/18/Code-Convention-Tooling-for-Better-Collaboratation/" data-id="cj2zamae20001ye7hre8p5qbt" class="article-share-link"><i class="fa fa-share"></i>Share</a>
<script>
(function ($) {
// Prevent duplicate binding
if (typeof(__SHARE_BUTTON_BINDED__) === 'undefined' || !__SHARE_BUTTON_BINDED__) {
__SHARE_BUTTON_BINDED__ = true;
} else {
return;
}
$('body').on('click', function() {
$('.article-share-box.on').removeClass('on');
}).on('click', '.article-share-link', function(e) {
e.stopPropagation();
var $this = $(this),
url = $this.attr('data-url'),
encodedUrl = encodeURIComponent(url),
id = 'article-share-box-' + $this.attr('data-id'),
offset = $this.offset(),
box;
if ($('#' + id).length) {
box = $('#' + id);
if (box.hasClass('on')){
box.removeClass('on');
return;
}
} else {
var html = [
'<div id="' + id + '" class="article-share-box">',
'<input class="article-share-input" value="' + url + '">',
'<div class="article-share-links">',
'<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="fa fa-twitter article-share-twitter" target="_blank" title="Twitter"></a>',
'<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="fa fa-facebook article-share-facebook" target="_blank" title="Facebook"></a>',
'<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="fa fa-pinterest article-share-pinterest" target="_blank" title="Pinterest"></a>',
'<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="fa fa-google article-share-google" target="_blank" title="Google+"></a>',
'</div>',
'</div>'
].join('');
box = $(html);
$('body').append(box);
}
$('.article-share-box.on').hide();
box.css({
top: offset.top + 25,
left: offset.left
}).addClass('on');
}).on('click', '.article-share-box', function (e) {
e.stopPropagation();
}).on('click', '.article-share-box-input', function () {
$(this).select();
}).on('click', '.article-share-box-link', function (e) {
e.preventDefault();
e.stopPropagation();
window.open(this.href, 'article-share-box-window-' + Date.now(), 'width=500,height=450');
});
})(jQuery);
</script>
<a href="https://minsooshin.github.io/2017/05/18/Code-Convention-Tooling-for-Better-Collaboratation/#comments" class="article-comment-link disqus-comment-count" data-disqus-url="https://minsooshin.github.io/2017/05/18/Code-Convention-Tooling-for-Better-Collaboratation/">Comments</a>
</footer>
</div>
</article>
<article id="post-React-Fiber-Reconciling-the-Rumours-with-the-Facts" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-inner">
<a href="/2017/05/11/React-Fiber-Reconciling-the-Rumours-with-the-Facts/" itemprop="url">
<img src="/images/react_fiber.png" class="article-banner" />
</a>
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2017/05/11/React-Fiber-Reconciling-the-Rumours-with-the-Facts/">React Fiber: 사실에 입각한 루머 정리</a>
</h1>
<div class="article-meta">
<div class="article-date">
<i class="fa fa-calendar"></i>
<a href="/2017/05/11/React-Fiber-Reconciling-the-Rumours-with-the-Facts/">
<time datetime="2017-05-11T16:29:34.000Z" itemprop="datePublished">2017-05-11</time>
</a>
</div>
<div class="article-category">
<i class="fa fa-folder"></i>
<a class="article-category-link" href="/categories/news/">news</a>
</div>
<div class="article-tag">
<i class="fa fa-tag"></i>
<a class="tag-link" href="/tags/JavaScript/">JavaScript</a>, <a class="tag-link" href="/tags/React/">React</a>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<p><p>최근 자바스크립트 프레임워크들이 당신이 주로 다루는 것이라면, 아마도 최근들어 사람들이 <strong>React Fiber</strong> 에 대해서 이야기 하는 것을 들어봤을 것 입니다.</p>
<p><strong>React</strong> 의 “다음 버전”을 학수 고대하고 그것을 적용하여 당신의 앱들을 모던 앱의 가볍고 빠르게 변화시키고 싶을지도 모릅니다. 또 한편으로 좌절감이 느껴질 정도로 빠른 자바스크립트 프레임워크들의 발생, 진화, 소멸의 속도를 보면, 이 <strong>Fiber</strong> 도 당신에게 극심한 혼돈을 야기할 수도 있습니다.</p>
<p>자, 심호흡 한 번 하시고 이제 시작하겠습니다. 이 글의 목적은 당신을 조금이라도 안도하게 하고 <strong>Fiber</strong> 에 관한 잘못된 상식들을 바로 잡고자 함입니다.</p></p>
<p class="article-more-link">
<a href="/2017/05/11/React-Fiber-Reconciling-the-Rumours-with-the-Facts/#more">Read More</a>
</p>
</div>
<footer class="article-footer">
<div class="share-container">
</div>
<a data-url="https://minsooshin.github.io/2017/05/11/React-Fiber-Reconciling-the-Rumours-with-the-Facts/" data-id="cj2zamaen0009ye7h8ud2uojj" class="article-share-link"><i class="fa fa-share"></i>Share</a>
<script>
(function ($) {
// Prevent duplicate binding
if (typeof(__SHARE_BUTTON_BINDED__) === 'undefined' || !__SHARE_BUTTON_BINDED__) {
__SHARE_BUTTON_BINDED__ = true;
} else {
return;
}
$('body').on('click', function() {
$('.article-share-box.on').removeClass('on');
}).on('click', '.article-share-link', function(e) {
e.stopPropagation();
var $this = $(this),
url = $this.attr('data-url'),
encodedUrl = encodeURIComponent(url),
id = 'article-share-box-' + $this.attr('data-id'),
offset = $this.offset(),
box;
if ($('#' + id).length) {
box = $('#' + id);
if (box.hasClass('on')){
box.removeClass('on');
return;
}
} else {
var html = [
'<div id="' + id + '" class="article-share-box">',
'<input class="article-share-input" value="' + url + '">',
'<div class="article-share-links">',
'<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="fa fa-twitter article-share-twitter" target="_blank" title="Twitter"></a>',
'<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="fa fa-facebook article-share-facebook" target="_blank" title="Facebook"></a>',
'<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="fa fa-pinterest article-share-pinterest" target="_blank" title="Pinterest"></a>',
'<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="fa fa-google article-share-google" target="_blank" title="Google+"></a>',
'</div>',
'</div>'
].join('');
box = $(html);
$('body').append(box);
}
$('.article-share-box.on').hide();
box.css({
top: offset.top + 25,
left: offset.left
}).addClass('on');
}).on('click', '.article-share-box', function (e) {
e.stopPropagation();
}).on('click', '.article-share-box-input', function () {
$(this).select();
}).on('click', '.article-share-box-link', function (e) {
e.preventDefault();
e.stopPropagation();
window.open(this.href, 'article-share-box-window-' + Date.now(), 'width=500,height=450');
});
})(jQuery);
</script>
<a href="https://minsooshin.github.io/2017/05/11/React-Fiber-Reconciling-the-Rumours-with-the-Facts/#comments" class="article-comment-link disqus-comment-count" data-disqus-url="https://minsooshin.github.io/2017/05/11/React-Fiber-Reconciling-the-Rumours-with-the-Facts/">Comments</a>
</footer>
</div>
</article>
<article id="post-Find-All-Duplicates-in-an-Array" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2017/05/08/Find-All-Duplicates-in-an-Array/">Find All Duplicates in an Array</a>
</h1>
<div class="article-meta">
<div class="article-date">
<i class="fa fa-calendar"></i>
<a href="/2017/05/08/Find-All-Duplicates-in-an-Array/">
<time datetime="2017-05-08T16:38:22.000Z" itemprop="datePublished">2017-05-08</time>
</a>
</div>
<div class="article-category">
<i class="fa fa-folder"></i>
<a class="article-category-link" href="/categories/leetcode/">leetcode</a>
</div>
<div class="article-tag">
<i class="fa fa-tag"></i>
<a class="tag-link" href="/tags/array/">array</a>, <a class="tag-link" href="/tags/medium/">medium</a>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<p>Source: <a href="https://leetcode.com/problems/find-all-duplicates-in-an-array/#/description" target="_blank" rel="external">leetcode 442. Find All Duplicates in an Array</a></p>
<p>Q. Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.</p>
<p>Find all the elements that appear twice in this array.</p>
<p>Could you do it without extra space and in O(n) runtime?</p>
<p><strong>Example:</strong><br>Input: [4, 3, 2, 7, 8, 2, 3, 1]<br>Output: [2, 3]</p>
<p><strong>Answer</strong><br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * @param {number[]} nums</div><div class="line"> * @return {number[]}</div><div class="line"> */</div><div class="line"><span class="keyword">export</span> <span class="keyword">default</span> <span class="function"><span class="keyword">function</span> <span class="title">findDuplicates</span> (<span class="params">nums</span>) </span>{</div><div class="line"> <span class="keyword">const</span> res = []</div><div class="line"> <span class="keyword">for</span> (<span class="keyword">let</span> i = <span class="number">0</span>; i < nums.length; i++) {</div><div class="line"> <span class="keyword">const</span> id = <span class="built_in">Math</span>.abs(nums[i]) - <span class="number">1</span></div><div class="line"> <span class="keyword">if</span> (nums[id] < <span class="number">0</span>) {</div><div class="line"> res.push(id + <span class="number">1</span>)</div><div class="line"> }</div><div class="line"> nums[id] = -nums[id]</div><div class="line"> }</div><div class="line"> <span class="keyword">return</span> res</div><div class="line">}</div></pre></td></tr></table></figure></p>
</div>
<footer class="article-footer">
<div class="share-container">
</div>
<a data-url="https://minsooshin.github.io/2017/05/08/Find-All-Duplicates-in-an-Array/" data-id="cj2zamaej0005ye7hnt60ybey" class="article-share-link"><i class="fa fa-share"></i>Share</a>
<script>
(function ($) {
// Prevent duplicate binding
if (typeof(__SHARE_BUTTON_BINDED__) === 'undefined' || !__SHARE_BUTTON_BINDED__) {
__SHARE_BUTTON_BINDED__ = true;
} else {
return;
}
$('body').on('click', function() {
$('.article-share-box.on').removeClass('on');
}).on('click', '.article-share-link', function(e) {
e.stopPropagation();
var $this = $(this),
url = $this.attr('data-url'),
encodedUrl = encodeURIComponent(url),
id = 'article-share-box-' + $this.attr('data-id'),
offset = $this.offset(),
box;
if ($('#' + id).length) {
box = $('#' + id);
if (box.hasClass('on')){
box.removeClass('on');
return;
}
} else {
var html = [
'<div id="' + id + '" class="article-share-box">',
'<input class="article-share-input" value="' + url + '">',
'<div class="article-share-links">',
'<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="fa fa-twitter article-share-twitter" target="_blank" title="Twitter"></a>',
'<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="fa fa-facebook article-share-facebook" target="_blank" title="Facebook"></a>',
'<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="fa fa-pinterest article-share-pinterest" target="_blank" title="Pinterest"></a>',
'<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="fa fa-google article-share-google" target="_blank" title="Google+"></a>',
'</div>',
'</div>'
].join('');
box = $(html);
$('body').append(box);
}
$('.article-share-box.on').hide();
box.css({
top: offset.top + 25,
left: offset.left
}).addClass('on');
}).on('click', '.article-share-box', function (e) {
e.stopPropagation();
}).on('click', '.article-share-box-input', function () {
$(this).select();
}).on('click', '.article-share-box-link', function (e) {
e.preventDefault();
e.stopPropagation();
window.open(this.href, 'article-share-box-window-' + Date.now(), 'width=500,height=450');
});
})(jQuery);
</script>
<a href="https://minsooshin.github.io/2017/05/08/Find-All-Duplicates-in-an-Array/#comments" class="article-comment-link disqus-comment-count" data-disqus-url="https://minsooshin.github.io/2017/05/08/Find-All-Duplicates-in-an-Array/">Comments</a>
</footer>
</div>
</article>
<article id="post-Convert-Sorted-Array-to-Binary-Search-Tree" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2017/05/04/Convert-Sorted-Array-to-Binary-Search-Tree/">Convert Sorted Array to Binary Search Tree</a>
</h1>
<div class="article-meta">
<div class="article-date">
<i class="fa fa-calendar"></i>
<a href="/2017/05/04/Convert-Sorted-Array-to-Binary-Search-Tree/">
<time datetime="2017-05-05T04:50:20.000Z" itemprop="datePublished">2017-05-04</time>
</a>
</div>
<div class="article-category">
<i class="fa fa-folder"></i>
<a class="article-category-link" href="/categories/leetcode/">leetcode</a>
</div>
<div class="article-tag">
<i class="fa fa-tag"></i>
<a class="tag-link" href="/tags/dfs/">dfs</a>, <a class="tag-link" href="/tags/easy/">easy</a>, <a class="tag-link" href="/tags/tree/">tree</a>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<p>Source: <a href="https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/#/description" target="_blank" rel="external">leetcode 108. Convert Sorted Array to Binary Search Tree</a></p>
<p>Q. Given an array where elements are sorted in ascending order, convert it to a height balanced BST.</p>
<p><strong>Answer</strong><br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * Definition for a binary tree node.</div><div class="line"> * function TreeNode(val) {</div><div class="line"> * this.val = val;</div><div class="line"> * this.left = this.right = null;</div><div class="line"> * }</div><div class="line"> */</div><div class="line"><span class="comment">/**</span></div><div class="line"> * @param {number[]} nums</div><div class="line"> * @return {TreeNode}</div><div class="line"> */</div><div class="line"><span class="keyword">export</span> <span class="keyword">default</span> <span class="function"><span class="keyword">function</span> <span class="title">sortedArrayToBST</span> (<span class="params">nums</span>) </span>{</div><div class="line"> <span class="keyword">if</span> (!nums.length) <span class="keyword">return</span> <span class="literal">null</span></div><div class="line"> <span class="function"><span class="keyword">function</span> <span class="title">helper</span>(<span class="params">nums, low, high</span>) </span>{</div><div class="line"> <span class="keyword">if</span> (low > high) {</div><div class="line"> <span class="keyword">return</span> <span class="literal">null</span></div><div class="line"> }</div><div class="line"> <span class="keyword">const</span> mid = (low + high) / <span class="number">2</span> | <span class="number">0</span></div><div class="line"> <span class="keyword">const</span> node = <span class="keyword">new</span> TreeNode(nums[mid])</div><div class="line"> node.left = helper(nums, low, mid - <span class="number">1</span>)</div><div class="line"> node.right = helper(nums, mid + <span class="number">1</span>, high)</div><div class="line"> <span class="keyword">return</span> node;</div><div class="line"> }</div><div class="line"> <span class="keyword">return</span> helper(nums, <span class="number">0</span>, nums.length - <span class="number">1</span>)</div><div class="line">}</div></pre></td></tr></table></figure></p>
</div>
<footer class="article-footer">
<div class="share-container">
</div>
<a data-url="https://minsooshin.github.io/2017/05/04/Convert-Sorted-Array-to-Binary-Search-Tree/" data-id="cj2zamael0006ye7hqn2371yu" class="article-share-link"><i class="fa fa-share"></i>Share</a>
<script>
(function ($) {
// Prevent duplicate binding
if (typeof(__SHARE_BUTTON_BINDED__) === 'undefined' || !__SHARE_BUTTON_BINDED__) {
__SHARE_BUTTON_BINDED__ = true;
} else {
return;
}
$('body').on('click', function() {
$('.article-share-box.on').removeClass('on');
}).on('click', '.article-share-link', function(e) {
e.stopPropagation();
var $this = $(this),
url = $this.attr('data-url'),
encodedUrl = encodeURIComponent(url),
id = 'article-share-box-' + $this.attr('data-id'),
offset = $this.offset(),
box;
if ($('#' + id).length) {
box = $('#' + id);
if (box.hasClass('on')){
box.removeClass('on');
return;
}
} else {
var html = [
'<div id="' + id + '" class="article-share-box">',
'<input class="article-share-input" value="' + url + '">',
'<div class="article-share-links">',
'<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="fa fa-twitter article-share-twitter" target="_blank" title="Twitter"></a>',
'<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="fa fa-facebook article-share-facebook" target="_blank" title="Facebook"></a>',
'<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="fa fa-pinterest article-share-pinterest" target="_blank" title="Pinterest"></a>',
'<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="fa fa-google article-share-google" target="_blank" title="Google+"></a>',
'</div>',
'</div>'
].join('');
box = $(html);
$('body').append(box);
}
$('.article-share-box.on').hide();
box.css({
top: offset.top + 25,
left: offset.left
}).addClass('on');
}).on('click', '.article-share-box', function (e) {
e.stopPropagation();
}).on('click', '.article-share-box-input', function () {
$(this).select();
}).on('click', '.article-share-box-link', function (e) {
e.preventDefault();
e.stopPropagation();
window.open(this.href, 'article-share-box-window-' + Date.now(), 'width=500,height=450');
});
})(jQuery);
</script>
<a href="https://minsooshin.github.io/2017/05/04/Convert-Sorted-Array-to-Binary-Search-Tree/#comments" class="article-comment-link disqus-comment-count" data-disqus-url="https://minsooshin.github.io/2017/05/04/Convert-Sorted-Array-to-Binary-Search-Tree/">Comments</a>
</footer>
</div>
</article>
<article id="post-Asynchronous-JavaScript-with-async-await" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-inner">
<a href="/2017/05/03/Asynchronous-JavaScript-with-async-await/" itemprop="url">
<img src="/images/async_await_cover.jpg" class="article-banner" />
</a>
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2017/05/03/Asynchronous-JavaScript-with-async-await/">Asynchronous JavaScript with async/await</a>
</h1>
<div class="article-meta">
<div class="article-date">
<i class="fa fa-calendar"></i>
<a href="/2017/05/03/Asynchronous-JavaScript-with-async-await/">
<time datetime="2017-05-04T04:37:32.000Z" itemprop="datePublished">2017-05-03</time>
</a>
</div>
<div class="article-category">
<i class="fa fa-folder"></i>
<a class="article-category-link" href="/categories/tutorial/">tutorial</a>
</div>
<div class="article-tag">
<i class="fa fa-tag"></i>
<a class="tag-link" href="/tags/ES7/">ES7</a>, <a class="tag-link" href="/tags/JavaScript/">JavaScript</a>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<p><h2 id="1-Write-an-Asynchronous-Function-with-async-await"><a href="#1-Write-an-Asynchronous-Function-with-async-await" class="headerlink" title="1. Write an Asynchronous Function with async/await"></a>1. Write an Asynchronous Function with async/await</h2><p>Here, we have short function that talks with a github API.</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">const</span> fetch = <span class="built_in">require</span>(<span class="string">'node-fetch'</span>)</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">showGithubUser</span>(<span class="params">handle</span>) </span>{</div><div class="line"> <span class="keyword">const</span> url = <span class="string">`https://api.github.com/users/<span class="subst">${handle}</span>`</span></div><div class="line"> fetch(url)</div><div class="line"> .then(<span class="function"><span class="params">resp</span> =></span> resp.json())</div><div class="line"> .then(<span class="function"><span class="params">user</span> =></span> {</div><div class="line"> <span class="built_in">console</span>.log(user.name)</div><div class="line"> <span class="built_in">console</span>.log(user.location)</div><div class="line"> })</div><div class="line">}</div><div class="line"></div><div class="line">showGithubUser(<span class="string">'minsooshin'</span>)</div></pre></td></tr></table></figure>
<p>It loads a specific user, and once the response comes back, it parses the body as JSON. Finally, user’s name and location are logged to the console.</p>
<p><img src="/images/async_screenshot1.png" alt="This is the result of execution"></p></p>
<p class="article-more-link">
<a href="/2017/05/03/Asynchronous-JavaScript-with-async-await/#more">Read More</a>
</p>
</div>
<footer class="article-footer">
<div class="share-container">
</div>
<a data-url="https://minsooshin.github.io/2017/05/03/Asynchronous-JavaScript-with-async-await/" data-id="cj2zamady0000ye7hlbop00x3" class="article-share-link"><i class="fa fa-share"></i>Share</a>
<script>
(function ($) {
// Prevent duplicate binding
if (typeof(__SHARE_BUTTON_BINDED__) === 'undefined' || !__SHARE_BUTTON_BINDED__) {
__SHARE_BUTTON_BINDED__ = true;
} else {
return;
}
$('body').on('click', function() {
$('.article-share-box.on').removeClass('on');
}).on('click', '.article-share-link', function(e) {
e.stopPropagation();
var $this = $(this),
url = $this.attr('data-url'),
encodedUrl = encodeURIComponent(url),
id = 'article-share-box-' + $this.attr('data-id'),
offset = $this.offset(),
box;
if ($('#' + id).length) {
box = $('#' + id);
if (box.hasClass('on')){
box.removeClass('on');
return;
}
} else {
var html = [
'<div id="' + id + '" class="article-share-box">',
'<input class="article-share-input" value="' + url + '">',
'<div class="article-share-links">',
'<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="fa fa-twitter article-share-twitter" target="_blank" title="Twitter"></a>',
'<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="fa fa-facebook article-share-facebook" target="_blank" title="Facebook"></a>',
'<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="fa fa-pinterest article-share-pinterest" target="_blank" title="Pinterest"></a>',
'<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="fa fa-google article-share-google" target="_blank" title="Google+"></a>',
'</div>',
'</div>'
].join('');
box = $(html);
$('body').append(box);
}
$('.article-share-box.on').hide();
box.css({
top: offset.top + 25,
left: offset.left
}).addClass('on');
}).on('click', '.article-share-box', function (e) {
e.stopPropagation();
}).on('click', '.article-share-box-input', function () {
$(this).select();
}).on('click', '.article-share-box-link', function (e) {
e.preventDefault();
e.stopPropagation();
window.open(this.href, 'article-share-box-window-' + Date.now(), 'width=500,height=450');
});
})(jQuery);
</script>
<a href="https://minsooshin.github.io/2017/05/03/Asynchronous-JavaScript-with-async-await/#comments" class="article-comment-link disqus-comment-count" data-disqus-url="https://minsooshin.github.io/2017/05/03/Asynchronous-JavaScript-with-async-await/">Comments</a>
</footer>
</div>
</article>
<article id="post-Search-Insert-Position" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2017/05/03/Search-Insert-Position/">Search Insert Position</a>
</h1>
<div class="article-meta">
<div class="article-date">
<i class="fa fa-calendar"></i>
<a href="/2017/05/03/Search-Insert-Position/">
<time datetime="2017-05-03T20:29:37.000Z" itemprop="datePublished">2017-05-03</time>
</a>
</div>
<div class="article-category">
<i class="fa fa-folder"></i>
<a class="article-category-link" href="/categories/leetcode/">leetcode</a>
</div>
<div class="article-tag">
<i class="fa fa-tag"></i>
<a class="tag-link" href="/tags/array/">array</a>, <a class="tag-link" href="/tags/binary-search/">binary search</a>, <a class="tag-link" href="/tags/easy/">easy</a>
</div>
</div>
</header>
<div class="article-entry" itemprop="articleBody">
<p>Source: <a href="https://leetcode.com/problems/search-insert-position/#/description" target="_blank" rel="external">leetcode 35. Search Insert Position</a></p>
<p>Q. Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.</p>
<p>You may assume no duplicates in the array.</p>
<p>Here are few examples.<br><code>[1, 3, 5, 6]</code>, 5 → 2<br><code>[1, 3, 5, 6]</code>, 2 → 1<br><code>[1, 3, 5, 6]</code>, 7 → 4<br><code>[1, 3, 5, 6]</code>, 0 → 0</p>
<p><strong>Answer</strong><br><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * @param {number[]} nums</div><div class="line"> * @param {number} target</div><div class="line"> * @return {number}</div><div class="line"> */</div><div class="line"><span class="keyword">export</span> <span class="keyword">default</span> <span class="function"><span class="keyword">function</span> <span class="title">searchInsert</span> (<span class="params">nums, target</span>) </span>{</div><div class="line"> <span class="keyword">let</span> low = <span class="number">0</span></div><div class="line"> <span class="keyword">let</span> high = nums.length - <span class="number">1</span></div><div class="line"> <span class="keyword">while</span> (low <= high) {</div><div class="line"> <span class="keyword">const</span> mid = (low + high) / <span class="number">2</span> | <span class="number">0</span></div><div class="line"> <span class="keyword">if</span> (nums[mid] === target) {</div><div class="line"> <span class="keyword">return</span> mid</div><div class="line"> } <span class="keyword">else</span> <span class="keyword">if</span> (nums[mid] > target) {</div><div class="line"> high = mid - <span class="number">1</span></div><div class="line"> } <span class="keyword">else</span> {</div><div class="line"> low = mid + <span class="number">1</span></div><div class="line"> }</div><div class="line"> }</div><div class="line"> <span class="keyword">return</span> low</div><div class="line">}</div></pre></td></tr></table></figure></p>
</div>
<footer class="article-footer">
<div class="share-container">
</div>
<a data-url="https://minsooshin.github.io/2017/05/03/Search-Insert-Position/" data-id="cj2zamaep000bye7hzxwmqprk" class="article-share-link"><i class="fa fa-share"></i>Share</a>
<script>
(function ($) {
// Prevent duplicate binding
if (typeof(__SHARE_BUTTON_BINDED__) === 'undefined' || !__SHARE_BUTTON_BINDED__) {
__SHARE_BUTTON_BINDED__ = true;
} else {
return;
}
$('body').on('click', function() {
$('.article-share-box.on').removeClass('on');
}).on('click', '.article-share-link', function(e) {
e.stopPropagation();
var $this = $(this),
url = $this.attr('data-url'),
encodedUrl = encodeURIComponent(url),
id = 'article-share-box-' + $this.attr('data-id'),
offset = $this.offset(),
box;
if ($('#' + id).length) {
box = $('#' + id);
if (box.hasClass('on')){
box.removeClass('on');
return;
}
} else {
var html = [
'<div id="' + id + '" class="article-share-box">',
'<input class="article-share-input" value="' + url + '">',
'<div class="article-share-links">',
'<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="fa fa-twitter article-share-twitter" target="_blank" title="Twitter"></a>',
'<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="fa fa-facebook article-share-facebook" target="_blank" title="Facebook"></a>',
'<a href="http://pinterest.com/pin/create/button/?url=' + encodedUrl + '" class="fa fa-pinterest article-share-pinterest" target="_blank" title="Pinterest"></a>',
'<a href="https://plus.google.com/share?url=' + encodedUrl + '" class="fa fa-google article-share-google" target="_blank" title="Google+"></a>',
'</div>',
'</div>'
].join('');
box = $(html);
$('body').append(box);
}
$('.article-share-box.on').hide();