aephiday commited on
Commit
4555371
·
verified ·
1 Parent(s): 94e6254

Upload 15 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ python.png filter=lfs diff=lfs merge=lfs -text
37
+ R.png filter=lfs diff=lfs merge=lfs -text
R.png ADDED

Git LFS Details

  • SHA256: 2fa3bf23e3168724b6e77657274668b519df4eb67d238f69a6048f700e760b3e
  • Pointer size: 131 Bytes
  • Size of remote file: 248 kB
RStudio-icon.png ADDED
cw0001evenodd.html ADDED
@@ -0,0 +1,720 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
3
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4
+ <meta charset="utf-8">
5
+ <meta name="generator" content="quarto-1.5.53">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
7
+ <title>1&nbsp; Even or Odd – Codewars Challenge</title>
8
+ <style>
9
+ code{white-space: pre-wrap;}
10
+ span.smallcaps{font-variant: small-caps;}
11
+ div.columns{display: flex; gap: min(4vw, 1.5em);}
12
+ div.column{flex: auto; overflow-x: auto;}
13
+ div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
14
+ ul.task-list{list-style: none;}
15
+ ul.task-list li input[type="checkbox"] {
16
+ width: 0.8em;
17
+ margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
18
+ vertical-align: middle;
19
+ }
20
+ /* CSS for syntax highlighting */
21
+ pre > code.sourceCode { white-space: pre; position: relative; }
22
+ pre > code.sourceCode > span { line-height: 1.25; }
23
+ pre > code.sourceCode > span:empty { height: 1.2em; }
24
+ .sourceCode { overflow: visible; }
25
+ code.sourceCode > span { color: inherit; text-decoration: inherit; }
26
+ div.sourceCode { margin: 1em 0; }
27
+ pre.sourceCode { margin: 0; }
28
+ @media screen {
29
+ div.sourceCode { overflow: auto; }
30
+ }
31
+ @media print {
32
+ pre > code.sourceCode { white-space: pre-wrap; }
33
+ pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
34
+ }
35
+ pre.numberSource code
36
+ { counter-reset: source-line 0; }
37
+ pre.numberSource code > span
38
+ { position: relative; left: -4em; counter-increment: source-line; }
39
+ pre.numberSource code > span > a:first-child::before
40
+ { content: counter(source-line);
41
+ position: relative; left: -1em; text-align: right; vertical-align: baseline;
42
+ border: none; display: inline-block;
43
+ -webkit-touch-callout: none; -webkit-user-select: none;
44
+ -khtml-user-select: none; -moz-user-select: none;
45
+ -ms-user-select: none; user-select: none;
46
+ padding: 0 4px; width: 4em;
47
+ }
48
+ pre.numberSource { margin-left: 3em; padding-left: 4px; }
49
+ div.sourceCode
50
+ { }
51
+ @media screen {
52
+ pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
53
+ }
54
+ </style>
55
+
56
+ <script src="site_libs/quarto-nav/quarto-nav.js"></script>
57
+ <script src="site_libs/quarto-nav/headroom.min.js"></script>
58
+ <script src="site_libs/clipboard/clipboard.min.js"></script>
59
+ <script src="site_libs/quarto-search/autocomplete.umd.js"></script>
60
+ <script src="site_libs/quarto-search/fuse.min.js"></script>
61
+ <script src="site_libs/quarto-search/quarto-search.js"></script>
62
+ <meta name="quarto:offset" content="./">
63
+ <link href="./cw0002multiply.html" rel="next">
64
+ <link href="./index.html" rel="prev">
65
+ <script src="site_libs/quarto-html/quarto.js"></script>
66
+ <script src="site_libs/quarto-html/popper.min.js"></script>
67
+ <script src="site_libs/quarto-html/tippy.umd.min.js"></script>
68
+ <script src="site_libs/quarto-html/anchor.min.js"></script>
69
+ <link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
70
+ <link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
71
+ <script src="site_libs/bootstrap/bootstrap.min.js"></script>
72
+ <link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
73
+ <link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light"><script id="quarto-search-options" type="application/json">{
74
+ "location": "sidebar",
75
+ "copy-button": false,
76
+ "collapse-after": 3,
77
+ "panel-placement": "start",
78
+ "type": "textbox",
79
+ "limit": 50,
80
+ "keyboard-shortcut": [
81
+ "f",
82
+ "/",
83
+ "s"
84
+ ],
85
+ "show-item-context": false,
86
+ "language": {
87
+ "search-no-results-text": "No results",
88
+ "search-matching-documents-text": "matching documents",
89
+ "search-copy-link-title": "Copy link to search",
90
+ "search-hide-matches-text": "Hide additional matches",
91
+ "search-more-match-text": "more match in this document",
92
+ "search-more-matches-text": "more matches in this document",
93
+ "search-clear-button-title": "Clear",
94
+ "search-text-placeholder": "",
95
+ "search-detached-cancel-button-title": "Cancel",
96
+ "search-submit-button-title": "Submit",
97
+ "search-label": "Search"
98
+ }
99
+ }</script><link rel="stylesheet" href="style.css">
100
+ <meta name="twitter:title" content="1&nbsp; Even or Odd – Codewars Challenge">
101
+ <meta name="twitter:description" content="">
102
+ <meta name="twitter:card" content="summary">
103
+ </head>
104
+ <body class="nav-sidebar floating">
105
+
106
+ <div id="quarto-search-results"></div>
107
+ <header id="quarto-header" class="headroom fixed-top"><nav class="quarto-secondary-nav"><div class="container-fluid d-flex">
108
+ <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" role="button" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
109
+ <i class="bi bi-layout-text-sidebar-reverse"></i>
110
+ </button>
111
+ <nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./cw0001evenodd.html">2025</a></li><li class="breadcrumb-item"><a href="./cw0001evenodd.html"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span></a></li></ol></nav>
112
+ <a class="flex-grow-1" role="navigation" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
113
+ </a>
114
+ <button type="button" class="btn quarto-search-button" aria-label="Search" onclick="window.quartoOpenSearch();">
115
+ <i class="bi bi-search"></i>
116
+ </button>
117
+ </div>
118
+ </nav></header><!-- content --><div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
119
+ <!-- sidebar -->
120
+ <nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal quarto-sidebar-collapse-item sidebar-navigation floating overflow-auto"><div class="pt-lg-2 mt-2 text-left sidebar-header">
121
+ <div class="sidebar-title mb-0 py-0">
122
+ <a href="./">Codewars Challenge</a>
123
+ <div class="sidebar-tools-main">
124
+ <a href="https://huggingface.co/spaces/aephidayatuloh/codewarschallenge/tree/main" title="Source Code" class="quarto-navigation-tool px-1" aria-label="Source Code"><i class="bi bi-git"></i></a>
125
+ </div>
126
+ </div>
127
+ </div>
128
+ <div class="mt-2 flex-shrink-0 align-items-center">
129
+ <div class="sidebar-search">
130
+ <div id="quarto-search" class="" title="Search"></div>
131
+ </div>
132
+ </div>
133
+ <div class="sidebar-menu-container">
134
+ <ul class="list-unstyled mt-1">
135
+ <li class="sidebar-item">
136
+ <div class="sidebar-item-container">
137
+ <a href="./index.html" class="sidebar-item-text sidebar-link">
138
+ <span class="menu-text">Pengantar</span></a>
139
+ </div>
140
+ </li>
141
+ <li class="sidebar-item sidebar-item-section">
142
+ <div class="sidebar-item-container">
143
+ <a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true">
144
+ <span class="menu-text">2025</span></a>
145
+ <a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true" aria-label="Toggle section">
146
+ <i class="bi bi-chevron-right ms-2"></i>
147
+ </a>
148
+ </div>
149
+ <ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
150
+ <li class="sidebar-item">
151
+ <div class="sidebar-item-container">
152
+ <a href="./cw0001evenodd.html" class="sidebar-item-text sidebar-link active">
153
+ <span class="menu-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span></span></a>
154
+ </div>
155
+ </li>
156
+ <li class="sidebar-item">
157
+ <div class="sidebar-item-container">
158
+ <a href="./cw0002multiply.html" class="sidebar-item-text sidebar-link">
159
+ <span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span></span></a>
160
+ </div>
161
+ </li>
162
+ <li class="sidebar-item">
163
+ <div class="sidebar-item-container">
164
+ <a href="./cw0003countsheep.html" class="sidebar-item-text sidebar-link">
165
+ <span class="menu-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Count Sheep</span></span></a>
166
+ </div>
167
+ </li>
168
+ <li class="sidebar-item">
169
+ <div class="sidebar-item-container">
170
+ <a href="./cw0004reducegrow.html" class="sidebar-item-text sidebar-link">
171
+ <span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow!</span></span></a>
172
+ </div>
173
+ </li>
174
+ <li class="sidebar-item">
175
+ <div class="sidebar-item-container">
176
+ <a href="./cw0005makenegative.html" class="sidebar-item-text sidebar-link">
177
+ <span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Return Negative</span></span></a>
178
+ </div>
179
+ </li>
180
+ </ul>
181
+ </li>
182
+ </ul>
183
+ </div>
184
+ </nav><div id="quarto-sidebar-glass" class="quarto-sidebar-collapse-item" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item"></div>
185
+ <!-- margin-sidebar -->
186
+ <div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
187
+ <nav id="TOC" role="doc-toc" class="toc-active" data-toc-expanded="99"><h2 id="toc-title">Table of contents</h2>
188
+
189
+ <ul>
190
+ <li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">1.1</span> Instruction</a></li>
191
+ <li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">1.2</span> YouTube Video</a></li>
192
+ <li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">1.3</span> Solution Code</a></li>
193
+ <li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">1.4</span> Test</a></li>
194
+ </ul></nav>
195
+ </div>
196
+ <!-- main -->
197
+ <main class="content" id="quarto-document-content"><header id="title-block-header" class="quarto-title-block default"><nav class="quarto-page-breadcrumbs quarto-title-breadcrumbs d-none d-lg-block" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./cw0001evenodd.html">2025</a></li><li class="breadcrumb-item"><a href="./cw0001evenodd.html"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span></a></li></ol></nav><div class="quarto-title">
198
+ <h1 class="title">
199
+ <span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span>
200
+ </h1>
201
+ </div>
202
+
203
+
204
+
205
+ <div class="quarto-title-meta">
206
+
207
+
208
+
209
+
210
+ </div>
211
+
212
+
213
+
214
+ </header><p><span class="badge rounded-pill quarto-badge">8Kyu</span> Tantangan #1/366 - 01 Feb 2025</p>
215
+ <p><a href="https://www.codewars.com/kata/53da3dbb4a5168369a0000fe" class="uri">https://www.codewars.com/kata/53da3dbb4a5168369a0000fe</a></p>
216
+ <h2 data-number="1.1" id="instruction" class="anchored">
217
+ <span class="header-section-number">1.1</span> Instruction</h2>
218
+ <blockquote class="blockquote">
219
+ <p>Create a function that takes an integer as an argument and returns <code>"Even"</code> for even numbers or <code>"Odd"</code> for odd numbers.</p>
220
+ </blockquote>
221
+ <h2 data-number="1.2" id="youtube-video" class="anchored">
222
+ <span class="header-section-number">1.2</span> YouTube Video</h2>
223
+ <div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/L8aczEhqymk" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
224
+ <h2 data-number="1.3" id="solution-code" class="anchored">
225
+ <span class="header-section-number">1.3</span> Solution Code</h2>
226
+ <p>Solusi bar-bar</p>
227
+ <div class="cell">
228
+ <div class="sourceCode" id="cb1"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">even_or_odd</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">n</span><span class="op">)</span> <span class="op">{</span></span>
229
+ <span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/MathFun.html">abs</a></span><span class="op">(</span><span class="va">n</span><span class="op">/</span><span class="fl">2</span> <span class="op">-</span> <span class="fu"><a href="https://rdrr.io/r/base/integer.html">as.integer</a></span><span class="op">(</span><span class="va">n</span><span class="op">/</span><span class="fl">2</span><span class="op">)</span><span class="op">)</span> <span class="op">==</span> <span class="fl">0.5</span>, <span class="st">"Odd"</span>, <span class="st">"Even"</span><span class="op">)</span></span>
230
+ <span><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
231
+ </div>
232
+ <p>Solusi simple</p>
233
+ <div class="cell">
234
+ <div class="sourceCode" id="cb2"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">even_or_odd</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">n</span><span class="op">)</span> <span class="op">{</span></span>
235
+ <span> <span class="co"># %% operator modulo</span></span>
236
+ <span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op">(</span><span class="va">n</span> <span class="op"><a href="https://rdrr.io/r/base/Arithmetic.html">%%</a></span> <span class="fl">2</span> <span class="op">==</span> <span class="fl">1</span>, <span class="st">"Odd"</span>, <span class="st">"Even"</span><span class="op">)</span></span>
237
+ <span><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
238
+ </div>
239
+ <div class="cell">
240
+ <div class="sourceCode" id="cb3"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">even_or_odd</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">n</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"Even"</span>, <span class="st">"Odd"</span><span class="op">)</span><span class="op">[</span><span class="va">n</span> <span class="op"><a href="https://rdrr.io/r/base/Arithmetic.html">%%</a></span> <span class="fl">2</span> <span class="op">+</span> <span class="fl">1</span><span class="op">]</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
241
+ </div>
242
+ <h2 data-number="1.4" id="test" class="anchored">
243
+ <span class="header-section-number">1.4</span> Test</h2>
244
+ <div class="cell">
245
+ <div class="sourceCode" id="cb4"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://testthat.r-lib.org">testthat</a></span><span class="op">)</span></span>
246
+ <span><span class="fu"><a href="https://testthat.r-lib.org/reference/test_that.html">test_that</a></span><span class="op">(</span><span class="st">'even_or_odd(1) returns "Odd"'</span>, <span class="op">{</span></span>
247
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">even_or_odd</span><span class="op">(</span><span class="fl">1</span><span class="op">)</span>, <span class="st">"Odd"</span><span class="op">)</span></span>
248
+ <span><span class="op">}</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
249
+ <div class="cell-output cell-output-stdout">
250
+ <pre><code>## Test passed 🎉</code></pre>
251
+ </div>
252
+ <div class="sourceCode" id="cb6"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu"><a href="https://testthat.r-lib.org/reference/test_that.html">test_that</a></span><span class="op">(</span><span class="st">'even_or_odd(2) returns "Even"'</span>, <span class="op">{</span></span>
253
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">even_or_odd</span><span class="op">(</span><span class="fl">2</span><span class="op">)</span>, <span class="st">"Even"</span><span class="op">)</span></span>
254
+ <span><span class="op">}</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
255
+ <div class="cell-output cell-output-stdout">
256
+ <pre><code>## Test passed 🥳</code></pre>
257
+ </div>
258
+ <div class="sourceCode" id="cb8"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu"><a href="https://testthat.r-lib.org/reference/test_that.html">test_that</a></span><span class="op">(</span><span class="st">'even_or_odd(0) returns "Even"'</span>, <span class="op">{</span></span>
259
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">even_or_odd</span><span class="op">(</span><span class="fl">0</span><span class="op">)</span>, <span class="st">"Even"</span><span class="op">)</span></span>
260
+ <span><span class="op">}</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
261
+ <div class="cell-output cell-output-stdout">
262
+ <pre><code>## Test passed 😸</code></pre>
263
+ </div>
264
+ <div class="sourceCode" id="cb10"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu"><a href="https://testthat.r-lib.org/reference/test_that.html">test_that</a></span><span class="op">(</span><span class="st">'even_or_odd(-1) returns "Odd"'</span>, <span class="op">{</span></span>
265
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">even_or_odd</span><span class="op">(</span><span class="op">-</span><span class="fl">1</span><span class="op">)</span>, <span class="st">"Odd"</span><span class="op">)</span></span>
266
+ <span><span class="op">}</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
267
+ <div class="cell-output cell-output-stdout">
268
+ <pre><code>## Test passed 🎉</code></pre>
269
+ </div>
270
+ <div class="sourceCode" id="cb12"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu"><a href="https://testthat.r-lib.org/reference/test_that.html">test_that</a></span><span class="op">(</span><span class="st">'even_or_odd(-2) returns "Even"'</span>, <span class="op">{</span></span>
271
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">even_or_odd</span><span class="op">(</span><span class="op">-</span><span class="fl">2</span><span class="op">)</span>, <span class="st">"Even"</span><span class="op">)</span></span>
272
+ <span><span class="op">}</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
273
+ <div class="cell-output cell-output-stdout">
274
+ <pre><code>## Test passed 🎊</code></pre>
275
+ </div>
276
+ </div>
277
+ <hr>
278
+ <p><strong>Supported by</strong></p>
279
+ <div class="quarto-figure quarto-figure-center">
280
+ <figure class="figure"><p><img src="new_starcore_logo.png" class="img-fluid figure-img"></p>
281
+ <figcaption>StarCore Analytics</figcaption></figure>
282
+ </div>
283
+
284
+
285
+
286
+ </main><!-- /main --><script id="quarto-html-after-body" type="application/javascript">
287
+ window.document.addEventListener("DOMContentLoaded", function (event) {
288
+ const toggleBodyColorMode = (bsSheetEl) => {
289
+ const mode = bsSheetEl.getAttribute("data-mode");
290
+ const bodyEl = window.document.querySelector("body");
291
+ if (mode === "dark") {
292
+ bodyEl.classList.add("quarto-dark");
293
+ bodyEl.classList.remove("quarto-light");
294
+ } else {
295
+ bodyEl.classList.add("quarto-light");
296
+ bodyEl.classList.remove("quarto-dark");
297
+ }
298
+ }
299
+ const toggleBodyColorPrimary = () => {
300
+ const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
301
+ if (bsSheetEl) {
302
+ toggleBodyColorMode(bsSheetEl);
303
+ }
304
+ }
305
+ toggleBodyColorPrimary();
306
+ const icon = "";
307
+ const anchorJS = new window.AnchorJS();
308
+ anchorJS.options = {
309
+ placement: 'right',
310
+ icon: icon
311
+ };
312
+ anchorJS.add('.anchored');
313
+ const isCodeAnnotation = (el) => {
314
+ for (const clz of el.classList) {
315
+ if (clz.startsWith('code-annotation-')) {
316
+ return true;
317
+ }
318
+ }
319
+ return false;
320
+ }
321
+ const onCopySuccess = function(e) {
322
+ // button target
323
+ const button = e.trigger;
324
+ // don't keep focus
325
+ button.blur();
326
+ // flash "checked"
327
+ button.classList.add('code-copy-button-checked');
328
+ var currentTitle = button.getAttribute("title");
329
+ button.setAttribute("title", "Copied!");
330
+ let tooltip;
331
+ if (window.bootstrap) {
332
+ button.setAttribute("data-bs-toggle", "tooltip");
333
+ button.setAttribute("data-bs-placement", "left");
334
+ button.setAttribute("data-bs-title", "Copied!");
335
+ tooltip = new bootstrap.Tooltip(button,
336
+ { trigger: "manual",
337
+ customClass: "code-copy-button-tooltip",
338
+ offset: [0, -8]});
339
+ tooltip.show();
340
+ }
341
+ setTimeout(function() {
342
+ if (tooltip) {
343
+ tooltip.hide();
344
+ button.removeAttribute("data-bs-title");
345
+ button.removeAttribute("data-bs-toggle");
346
+ button.removeAttribute("data-bs-placement");
347
+ }
348
+ button.setAttribute("title", currentTitle);
349
+ button.classList.remove('code-copy-button-checked');
350
+ }, 1000);
351
+ // clear code selection
352
+ e.clearSelection();
353
+ }
354
+ const getTextToCopy = function(trigger) {
355
+ const codeEl = trigger.previousElementSibling.cloneNode(true);
356
+ for (const childEl of codeEl.children) {
357
+ if (isCodeAnnotation(childEl)) {
358
+ childEl.remove();
359
+ }
360
+ }
361
+ return codeEl.innerText;
362
+ }
363
+ const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
364
+ text: getTextToCopy
365
+ });
366
+ clipboard.on('success', onCopySuccess);
367
+ if (window.document.getElementById('quarto-embedded-source-code-modal')) {
368
+ // For code content inside modals, clipBoardJS needs to be initialized with a container option
369
+ // TODO: Check when it could be a function (https://github.com/zenorocha/clipboard.js/issues/860)
370
+ const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
371
+ text: getTextToCopy,
372
+ container: window.document.getElementById('quarto-embedded-source-code-modal')
373
+ });
374
+ clipboardModal.on('success', onCopySuccess);
375
+ }
376
+ var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
377
+ var mailtoRegex = new RegExp(/^mailto:/);
378
+ var filterRegex = new RegExp("https:\/\/huggingface\.co\/spaces\/aephidayatuloh\/codewarschallenge\/");
379
+ var isInternal = (href) => {
380
+ return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
381
+ }
382
+ // Inspect non-navigation links and adorn them if external
383
+ var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
384
+ for (var i=0; i<links.length; i++) {
385
+ const link = links[i];
386
+ if (!isInternal(link.href)) {
387
+ // undo the damage that might have been done by quarto-nav.js in the case of
388
+ // links that we want to consider external
389
+ if (link.dataset.originalHref !== undefined) {
390
+ link.href = link.dataset.originalHref;
391
+ }
392
+ }
393
+ }
394
+ function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
395
+ const config = {
396
+ allowHTML: true,
397
+ maxWidth: 500,
398
+ delay: 100,
399
+ arrow: false,
400
+ appendTo: function(el) {
401
+ return el.parentElement;
402
+ },
403
+ interactive: true,
404
+ interactiveBorder: 10,
405
+ theme: 'quarto',
406
+ placement: 'bottom-start',
407
+ };
408
+ if (contentFn) {
409
+ config.content = contentFn;
410
+ }
411
+ if (onTriggerFn) {
412
+ config.onTrigger = onTriggerFn;
413
+ }
414
+ if (onUntriggerFn) {
415
+ config.onUntrigger = onUntriggerFn;
416
+ }
417
+ window.tippy(el, config);
418
+ }
419
+ const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
420
+ for (var i=0; i<noterefs.length; i++) {
421
+ const ref = noterefs[i];
422
+ tippyHover(ref, function() {
423
+ // use id or data attribute instead here
424
+ let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
425
+ try { href = new URL(href).hash; } catch {}
426
+ const id = href.replace(/^#\/?/, "");
427
+ const note = window.document.getElementById(id);
428
+ if (note) {
429
+ return note.innerHTML;
430
+ } else {
431
+ return "";
432
+ }
433
+ });
434
+ }
435
+ const xrefs = window.document.querySelectorAll('a.quarto-xref');
436
+ const processXRef = (id, note) => {
437
+ // Strip column container classes
438
+ const stripColumnClz = (el) => {
439
+ el.classList.remove("page-full", "page-columns");
440
+ if (el.children) {
441
+ for (const child of el.children) {
442
+ stripColumnClz(child);
443
+ }
444
+ }
445
+ }
446
+ stripColumnClz(note)
447
+ if (id === null || id.startsWith('sec-')) {
448
+ // Special case sections, only their first couple elements
449
+ const container = document.createElement("div");
450
+ if (note.children && note.children.length > 2) {
451
+ container.appendChild(note.children[0].cloneNode(true));
452
+ for (let i = 1; i < note.children.length; i++) {
453
+ const child = note.children[i];
454
+ if (child.tagName === "P" && child.innerText === "") {
455
+ continue;
456
+ } else {
457
+ container.appendChild(child.cloneNode(true));
458
+ break;
459
+ }
460
+ }
461
+ if (window.Quarto?.typesetMath) {
462
+ window.Quarto.typesetMath(container);
463
+ }
464
+ return container.innerHTML
465
+ } else {
466
+ if (window.Quarto?.typesetMath) {
467
+ window.Quarto.typesetMath(note);
468
+ }
469
+ return note.innerHTML;
470
+ }
471
+ } else {
472
+ // Remove any anchor links if they are present
473
+ const anchorLink = note.querySelector('a.anchorjs-link');
474
+ if (anchorLink) {
475
+ anchorLink.remove();
476
+ }
477
+ if (window.Quarto?.typesetMath) {
478
+ window.Quarto.typesetMath(note);
479
+ }
480
+ // TODO in 1.5, we should make sure this works without a callout special case
481
+ if (note.classList.contains("callout")) {
482
+ return note.outerHTML;
483
+ } else {
484
+ return note.innerHTML;
485
+ }
486
+ }
487
+ }
488
+ for (var i=0; i<xrefs.length; i++) {
489
+ const xref = xrefs[i];
490
+ tippyHover(xref, undefined, function(instance) {
491
+ instance.disable();
492
+ let url = xref.getAttribute('href');
493
+ let hash = undefined;
494
+ if (url.startsWith('#')) {
495
+ hash = url;
496
+ } else {
497
+ try { hash = new URL(url).hash; } catch {}
498
+ }
499
+ if (hash) {
500
+ const id = hash.replace(/^#\/?/, "");
501
+ const note = window.document.getElementById(id);
502
+ if (note !== null) {
503
+ try {
504
+ const html = processXRef(id, note.cloneNode(true));
505
+ instance.setContent(html);
506
+ } finally {
507
+ instance.enable();
508
+ instance.show();
509
+ }
510
+ } else {
511
+ // See if we can fetch this
512
+ fetch(url.split('#')[0])
513
+ .then(res => res.text())
514
+ .then(html => {
515
+ const parser = new DOMParser();
516
+ const htmlDoc = parser.parseFromString(html, "text/html");
517
+ const note = htmlDoc.getElementById(id);
518
+ if (note !== null) {
519
+ const html = processXRef(id, note);
520
+ instance.setContent(html);
521
+ }
522
+ }).finally(() => {
523
+ instance.enable();
524
+ instance.show();
525
+ });
526
+ }
527
+ } else {
528
+ // See if we can fetch a full url (with no hash to target)
529
+ // This is a special case and we should probably do some content thinning / targeting
530
+ fetch(url)
531
+ .then(res => res.text())
532
+ .then(html => {
533
+ const parser = new DOMParser();
534
+ const htmlDoc = parser.parseFromString(html, "text/html");
535
+ const note = htmlDoc.querySelector('main.content');
536
+ if (note !== null) {
537
+ // This should only happen for chapter cross references
538
+ // (since there is no id in the URL)
539
+ // remove the first header
540
+ if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
541
+ note.children[0].remove();
542
+ }
543
+ const html = processXRef(null, note);
544
+ instance.setContent(html);
545
+ }
546
+ }).finally(() => {
547
+ instance.enable();
548
+ instance.show();
549
+ });
550
+ }
551
+ }, function(instance) {
552
+ });
553
+ }
554
+ let selectedAnnoteEl;
555
+ const selectorForAnnotation = ( cell, annotation) => {
556
+ let cellAttr = 'data-code-cell="' + cell + '"';
557
+ let lineAttr = 'data-code-annotation="' + annotation + '"';
558
+ const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
559
+ return selector;
560
+ }
561
+ const selectCodeLines = (annoteEl) => {
562
+ const doc = window.document;
563
+ const targetCell = annoteEl.getAttribute("data-target-cell");
564
+ const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
565
+ const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
566
+ const lines = annoteSpan.getAttribute("data-code-lines").split(",");
567
+ const lineIds = lines.map((line) => {
568
+ return targetCell + "-" + line;
569
+ })
570
+ let top = null;
571
+ let height = null;
572
+ let parent = null;
573
+ if (lineIds.length > 0) {
574
+ //compute the position of the single el (top and bottom and make a div)
575
+ const el = window.document.getElementById(lineIds[0]);
576
+ top = el.offsetTop;
577
+ height = el.offsetHeight;
578
+ parent = el.parentElement.parentElement;
579
+ if (lineIds.length > 1) {
580
+ const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
581
+ const bottom = lastEl.offsetTop + lastEl.offsetHeight;
582
+ height = bottom - top;
583
+ }
584
+ if (top !== null && height !== null && parent !== null) {
585
+ // cook up a div (if necessary) and position it
586
+ let div = window.document.getElementById("code-annotation-line-highlight");
587
+ if (div === null) {
588
+ div = window.document.createElement("div");
589
+ div.setAttribute("id", "code-annotation-line-highlight");
590
+ div.style.position = 'absolute';
591
+ parent.appendChild(div);
592
+ }
593
+ div.style.top = top - 2 + "px";
594
+ div.style.height = height + 4 + "px";
595
+ div.style.left = 0;
596
+ let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
597
+ if (gutterDiv === null) {
598
+ gutterDiv = window.document.createElement("div");
599
+ gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
600
+ gutterDiv.style.position = 'absolute';
601
+ const codeCell = window.document.getElementById(targetCell);
602
+ const gutter = codeCell.querySelector('.code-annotation-gutter');
603
+ gutter.appendChild(gutterDiv);
604
+ }
605
+ gutterDiv.style.top = top - 2 + "px";
606
+ gutterDiv.style.height = height + 4 + "px";
607
+ }
608
+ selectedAnnoteEl = annoteEl;
609
+ }
610
+ };
611
+ const unselectCodeLines = () => {
612
+ const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
613
+ elementsIds.forEach((elId) => {
614
+ const div = window.document.getElementById(elId);
615
+ if (div) {
616
+ div.remove();
617
+ }
618
+ });
619
+ selectedAnnoteEl = undefined;
620
+ };
621
+ // Handle positioning of the toggle
622
+ window.addEventListener(
623
+ "resize",
624
+ throttle(() => {
625
+ elRect = undefined;
626
+ if (selectedAnnoteEl) {
627
+ selectCodeLines(selectedAnnoteEl);
628
+ }
629
+ }, 10)
630
+ );
631
+ function throttle(fn, ms) {
632
+ let throttle = false;
633
+ let timer;
634
+ return (...args) => {
635
+ if(!throttle) { // first call gets through
636
+ fn.apply(this, args);
637
+ throttle = true;
638
+ } else { // all the others get throttled
639
+ if(timer) clearTimeout(timer); // cancel #2
640
+ timer = setTimeout(() => {
641
+ fn.apply(this, args);
642
+ timer = throttle = false;
643
+ }, ms);
644
+ }
645
+ };
646
+ }
647
+ // Attach click handler to the DT
648
+ const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
649
+ for (const annoteDlNode of annoteDls) {
650
+ annoteDlNode.addEventListener('click', (event) => {
651
+ const clickedEl = event.target;
652
+ if (clickedEl !== selectedAnnoteEl) {
653
+ unselectCodeLines();
654
+ const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
655
+ if (activeEl) {
656
+ activeEl.classList.remove('code-annotation-active');
657
+ }
658
+ selectCodeLines(clickedEl);
659
+ clickedEl.classList.add('code-annotation-active');
660
+ } else {
661
+ // Unselect the line
662
+ unselectCodeLines();
663
+ clickedEl.classList.remove('code-annotation-active');
664
+ }
665
+ });
666
+ }
667
+ const findCites = (el) => {
668
+ const parentEl = el.parentElement;
669
+ if (parentEl) {
670
+ const cites = parentEl.dataset.cites;
671
+ if (cites) {
672
+ return {
673
+ el,
674
+ cites: cites.split(' ')
675
+ };
676
+ } else {
677
+ return findCites(el.parentElement)
678
+ }
679
+ } else {
680
+ return undefined;
681
+ }
682
+ };
683
+ var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
684
+ for (var i=0; i<bibliorefs.length; i++) {
685
+ const ref = bibliorefs[i];
686
+ const citeInfo = findCites(ref);
687
+ if (citeInfo) {
688
+ tippyHover(citeInfo.el, function() {
689
+ var popup = window.document.createElement('div');
690
+ citeInfo.cites.forEach(function(cite) {
691
+ var citeDiv = window.document.createElement('div');
692
+ citeDiv.classList.add('hanging-indent');
693
+ citeDiv.classList.add('csl-entry');
694
+ var biblioDiv = window.document.getElementById('ref-' + cite);
695
+ if (biblioDiv) {
696
+ citeDiv.innerHTML = biblioDiv.innerHTML;
697
+ }
698
+ popup.appendChild(citeDiv);
699
+ });
700
+ return popup.innerHTML;
701
+ });
702
+ }
703
+ }
704
+ });
705
+ </script><nav class="page-navigation"><div class="nav-page nav-page-previous">
706
+ <a href="./index.html" class="pagination-link" aria-label="Pengantar">
707
+ <i class="bi bi-arrow-left-short"></i> <span class="nav-page-text">Pengantar</span>
708
+ </a>
709
+ </div>
710
+ <div class="nav-page nav-page-next">
711
+ <a href="./cw0002multiply.html" class="pagination-link" aria-label="Multiply">
712
+ <span class="nav-page-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span></span> <i class="bi bi-arrow-right-short"></i>
713
+ </a>
714
+ </div>
715
+ </nav>
716
+ </div> <!-- /content -->
717
+
718
+
719
+
720
+ </body></html>
cw0002multiply.html ADDED
@@ -0,0 +1,698 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
3
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4
+ <meta charset="utf-8">
5
+ <meta name="generator" content="quarto-1.5.53">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
7
+ <title>2&nbsp; Multiply – Codewars Challenge</title>
8
+ <style>
9
+ code{white-space: pre-wrap;}
10
+ span.smallcaps{font-variant: small-caps;}
11
+ div.columns{display: flex; gap: min(4vw, 1.5em);}
12
+ div.column{flex: auto; overflow-x: auto;}
13
+ div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
14
+ ul.task-list{list-style: none;}
15
+ ul.task-list li input[type="checkbox"] {
16
+ width: 0.8em;
17
+ margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
18
+ vertical-align: middle;
19
+ }
20
+ /* CSS for syntax highlighting */
21
+ pre > code.sourceCode { white-space: pre; position: relative; }
22
+ pre > code.sourceCode > span { line-height: 1.25; }
23
+ pre > code.sourceCode > span:empty { height: 1.2em; }
24
+ .sourceCode { overflow: visible; }
25
+ code.sourceCode > span { color: inherit; text-decoration: inherit; }
26
+ div.sourceCode { margin: 1em 0; }
27
+ pre.sourceCode { margin: 0; }
28
+ @media screen {
29
+ div.sourceCode { overflow: auto; }
30
+ }
31
+ @media print {
32
+ pre > code.sourceCode { white-space: pre-wrap; }
33
+ pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
34
+ }
35
+ pre.numberSource code
36
+ { counter-reset: source-line 0; }
37
+ pre.numberSource code > span
38
+ { position: relative; left: -4em; counter-increment: source-line; }
39
+ pre.numberSource code > span > a:first-child::before
40
+ { content: counter(source-line);
41
+ position: relative; left: -1em; text-align: right; vertical-align: baseline;
42
+ border: none; display: inline-block;
43
+ -webkit-touch-callout: none; -webkit-user-select: none;
44
+ -khtml-user-select: none; -moz-user-select: none;
45
+ -ms-user-select: none; user-select: none;
46
+ padding: 0 4px; width: 4em;
47
+ }
48
+ pre.numberSource { margin-left: 3em; padding-left: 4px; }
49
+ div.sourceCode
50
+ { }
51
+ @media screen {
52
+ pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
53
+ }
54
+ </style>
55
+
56
+ <script src="site_libs/quarto-nav/quarto-nav.js"></script>
57
+ <script src="site_libs/quarto-nav/headroom.min.js"></script>
58
+ <script src="site_libs/clipboard/clipboard.min.js"></script>
59
+ <script src="site_libs/quarto-search/autocomplete.umd.js"></script>
60
+ <script src="site_libs/quarto-search/fuse.min.js"></script>
61
+ <script src="site_libs/quarto-search/quarto-search.js"></script>
62
+ <meta name="quarto:offset" content="./">
63
+ <link href="./cw0003countsheep.html" rel="next">
64
+ <link href="./cw0001evenodd.html" rel="prev">
65
+ <script src="site_libs/quarto-html/quarto.js"></script>
66
+ <script src="site_libs/quarto-html/popper.min.js"></script>
67
+ <script src="site_libs/quarto-html/tippy.umd.min.js"></script>
68
+ <script src="site_libs/quarto-html/anchor.min.js"></script>
69
+ <link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
70
+ <link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
71
+ <script src="site_libs/bootstrap/bootstrap.min.js"></script>
72
+ <link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
73
+ <link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light"><script id="quarto-search-options" type="application/json">{
74
+ "location": "sidebar",
75
+ "copy-button": false,
76
+ "collapse-after": 3,
77
+ "panel-placement": "start",
78
+ "type": "textbox",
79
+ "limit": 50,
80
+ "keyboard-shortcut": [
81
+ "f",
82
+ "/",
83
+ "s"
84
+ ],
85
+ "show-item-context": false,
86
+ "language": {
87
+ "search-no-results-text": "No results",
88
+ "search-matching-documents-text": "matching documents",
89
+ "search-copy-link-title": "Copy link to search",
90
+ "search-hide-matches-text": "Hide additional matches",
91
+ "search-more-match-text": "more match in this document",
92
+ "search-more-matches-text": "more matches in this document",
93
+ "search-clear-button-title": "Clear",
94
+ "search-text-placeholder": "",
95
+ "search-detached-cancel-button-title": "Cancel",
96
+ "search-submit-button-title": "Submit",
97
+ "search-label": "Search"
98
+ }
99
+ }</script><link rel="stylesheet" href="style.css">
100
+ <meta name="twitter:title" content="2&nbsp; Multiply – Codewars Challenge">
101
+ <meta name="twitter:description" content="">
102
+ <meta name="twitter:card" content="summary">
103
+ </head>
104
+ <body class="nav-sidebar floating">
105
+
106
+ <div id="quarto-search-results"></div>
107
+ <header id="quarto-header" class="headroom fixed-top"><nav class="quarto-secondary-nav"><div class="container-fluid d-flex">
108
+ <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" role="button" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
109
+ <i class="bi bi-layout-text-sidebar-reverse"></i>
110
+ </button>
111
+ <nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./cw0001evenodd.html">2025</a></li><li class="breadcrumb-item"><a href="./cw0002multiply.html"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span></a></li></ol></nav>
112
+ <a class="flex-grow-1" role="navigation" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
113
+ </a>
114
+ <button type="button" class="btn quarto-search-button" aria-label="Search" onclick="window.quartoOpenSearch();">
115
+ <i class="bi bi-search"></i>
116
+ </button>
117
+ </div>
118
+ </nav></header><!-- content --><div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
119
+ <!-- sidebar -->
120
+ <nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal quarto-sidebar-collapse-item sidebar-navigation floating overflow-auto"><div class="pt-lg-2 mt-2 text-left sidebar-header">
121
+ <div class="sidebar-title mb-0 py-0">
122
+ <a href="./">Codewars Challenge</a>
123
+ <div class="sidebar-tools-main">
124
+ <a href="https://huggingface.co/spaces/aephidayatuloh/codewarschallenge/tree/main" title="Source Code" class="quarto-navigation-tool px-1" aria-label="Source Code"><i class="bi bi-git"></i></a>
125
+ </div>
126
+ </div>
127
+ </div>
128
+ <div class="mt-2 flex-shrink-0 align-items-center">
129
+ <div class="sidebar-search">
130
+ <div id="quarto-search" class="" title="Search"></div>
131
+ </div>
132
+ </div>
133
+ <div class="sidebar-menu-container">
134
+ <ul class="list-unstyled mt-1">
135
+ <li class="sidebar-item">
136
+ <div class="sidebar-item-container">
137
+ <a href="./index.html" class="sidebar-item-text sidebar-link">
138
+ <span class="menu-text">Pengantar</span></a>
139
+ </div>
140
+ </li>
141
+ <li class="sidebar-item sidebar-item-section">
142
+ <div class="sidebar-item-container">
143
+ <a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true">
144
+ <span class="menu-text">2025</span></a>
145
+ <a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true" aria-label="Toggle section">
146
+ <i class="bi bi-chevron-right ms-2"></i>
147
+ </a>
148
+ </div>
149
+ <ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
150
+ <li class="sidebar-item">
151
+ <div class="sidebar-item-container">
152
+ <a href="./cw0001evenodd.html" class="sidebar-item-text sidebar-link">
153
+ <span class="menu-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span></span></a>
154
+ </div>
155
+ </li>
156
+ <li class="sidebar-item">
157
+ <div class="sidebar-item-container">
158
+ <a href="./cw0002multiply.html" class="sidebar-item-text sidebar-link active">
159
+ <span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span></span></a>
160
+ </div>
161
+ </li>
162
+ <li class="sidebar-item">
163
+ <div class="sidebar-item-container">
164
+ <a href="./cw0003countsheep.html" class="sidebar-item-text sidebar-link">
165
+ <span class="menu-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Count Sheep</span></span></a>
166
+ </div>
167
+ </li>
168
+ <li class="sidebar-item">
169
+ <div class="sidebar-item-container">
170
+ <a href="./cw0004reducegrow.html" class="sidebar-item-text sidebar-link">
171
+ <span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow!</span></span></a>
172
+ </div>
173
+ </li>
174
+ <li class="sidebar-item">
175
+ <div class="sidebar-item-container">
176
+ <a href="./cw0005makenegative.html" class="sidebar-item-text sidebar-link">
177
+ <span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Return Negative</span></span></a>
178
+ </div>
179
+ </li>
180
+ </ul>
181
+ </li>
182
+ </ul>
183
+ </div>
184
+ </nav><div id="quarto-sidebar-glass" class="quarto-sidebar-collapse-item" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item"></div>
185
+ <!-- margin-sidebar -->
186
+ <div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
187
+ <nav id="TOC" role="doc-toc" class="toc-active" data-toc-expanded="99"><h2 id="toc-title">Table of contents</h2>
188
+
189
+ <ul>
190
+ <li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">2.1</span> Instruction</a></li>
191
+ <li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">2.2</span> YouTube Video</a></li>
192
+ <li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">2.3</span> Solution Code</a></li>
193
+ <li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">2.4</span> Test</a></li>
194
+ </ul></nav>
195
+ </div>
196
+ <!-- main -->
197
+ <main class="content" id="quarto-document-content"><header id="title-block-header" class="quarto-title-block default"><nav class="quarto-page-breadcrumbs quarto-title-breadcrumbs d-none d-lg-block" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./cw0001evenodd.html">2025</a></li><li class="breadcrumb-item"><a href="./cw0002multiply.html"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span></a></li></ol></nav><div class="quarto-title">
198
+ <h1 class="title">
199
+ <span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span>
200
+ </h1>
201
+ </div>
202
+
203
+
204
+
205
+ <div class="quarto-title-meta">
206
+
207
+
208
+
209
+
210
+ </div>
211
+
212
+
213
+
214
+ </header><p><span class="badge rounded-pill quarto-badge">8Kyu</span> Tantangan #2/366 - 02 Feb 2025</p>
215
+ <p><a href="https://www.codewars.com/kata/50654ddff44f800200000004" class="uri">https://www.codewars.com/kata/50654ddff44f800200000004</a></p>
216
+ <h2 data-number="2.1" id="instruction" class="anchored">
217
+ <span class="header-section-number">2.1</span> Instruction</h2>
218
+ <blockquote class="blockquote">
219
+ <p>This code does not execute properly. Try to figure out why.</p>
220
+ </blockquote>
221
+ <div class="cell">
222
+ <div class="sourceCode" id="cb1"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">mul</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">a</span>, <span class="va">b</span><span class="op">)</span> <span class="op">{</span></span>
223
+ <span> <span class="va">a</span> <span class="op">*</span> <span class="va">c</span> <span class="co"># try to figure out why it doesn't work!</span></span>
224
+ <span><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
225
+ </div>
226
+ <h2 data-number="2.2" id="youtube-video" class="anchored">
227
+ <span class="header-section-number">2.2</span> YouTube Video</h2>
228
+ <div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/L8aczEhqymk" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
229
+ <h2 data-number="2.3" id="solution-code" class="anchored">
230
+ <span class="header-section-number">2.3</span> Solution Code</h2>
231
+ <p>Karena argumen dari function <code>mul()</code> adalah <code>a</code> dan <code>b</code> sedangkan operasi perkalian di dalamnya menggunakan <code>c</code> yang belum diketahui dan tidak ada objek tersebut.</p>
232
+ <p><strong>Solusi</strong>: ganti objek <code>c</code> di dalam function <code>mul()</code> dengan <code>b</code> dari argumen function tersebut.</p>
233
+ <div class="cell">
234
+ <div class="sourceCode" id="cb2"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">mul</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">a</span>, <span class="va">b</span><span class="op">)</span> <span class="op">{</span></span>
235
+ <span> <span class="va">a</span> <span class="op">*</span> <span class="va">b</span> </span>
236
+ <span><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
237
+ </div>
238
+ <h2 data-number="2.4" id="test" class="anchored">
239
+ <span class="header-section-number">2.4</span> Test</h2>
240
+ <div class="cell">
241
+ <div class="sourceCode" id="cb3"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://testthat.r-lib.org">testthat</a></span><span class="op">)</span></span>
242
+ <span></span>
243
+ <span><span class="fu"><a href="https://testthat.r-lib.org/reference/test_that.html">test_that</a></span><span class="op">(</span><span class="st">"test for associativity of multiplication"</span>, <span class="op">{</span></span>
244
+ <span> <span class="va">a</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/Uniform.html">runif</a></span><span class="op">(</span><span class="fl">1</span>, <span class="fl">0</span>, <span class="fl">10000</span><span class="op">)</span></span>
245
+ <span> <span class="va">b</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/Uniform.html">runif</a></span><span class="op">(</span><span class="fl">1</span>, <span class="fl">0</span>, <span class="fl">10000</span><span class="op">)</span></span>
246
+ <span> <span class="va">c</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/stats/Uniform.html">runif</a></span><span class="op">(</span><span class="fl">1</span>, <span class="fl">0</span>, <span class="fl">10000</span><span class="op">)</span></span>
247
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">mul</span><span class="op">(</span><span class="va">a</span>, <span class="va">b</span><span class="op">)</span>, <span class="va">a</span> <span class="op">*</span> <span class="va">b</span><span class="op">)</span></span>
248
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">mul</span><span class="op">(</span><span class="fu">mul</span><span class="op">(</span><span class="va">a</span>, <span class="va">b</span><span class="op">)</span>, <span class="va">c</span><span class="op">)</span>, <span class="va">a</span> <span class="op">*</span> <span class="va">b</span> <span class="op">*</span> <span class="va">c</span><span class="op">)</span></span>
249
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">mul</span><span class="op">(</span><span class="va">a</span>, <span class="fu">mul</span><span class="op">(</span><span class="va">b</span>, <span class="va">c</span><span class="op">)</span><span class="op">)</span>, <span class="va">a</span> <span class="op">*</span> <span class="va">b</span> <span class="op">*</span> <span class="va">c</span><span class="op">)</span></span>
250
+ <span><span class="op">}</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
251
+ <div class="cell-output cell-output-stdout">
252
+ <pre><code>## Test passed 🥇</code></pre>
253
+ </div>
254
+ </div>
255
+ <hr>
256
+ <p><strong>Supported by</strong></p>
257
+ <div class="quarto-figure quarto-figure-center">
258
+ <figure class="figure"><p><img src="new_starcore_logo.png" class="img-fluid figure-img"></p>
259
+ <figcaption>StarCore Analytics</figcaption></figure>
260
+ </div>
261
+
262
+
263
+
264
+ </main><!-- /main --><script id="quarto-html-after-body" type="application/javascript">
265
+ window.document.addEventListener("DOMContentLoaded", function (event) {
266
+ const toggleBodyColorMode = (bsSheetEl) => {
267
+ const mode = bsSheetEl.getAttribute("data-mode");
268
+ const bodyEl = window.document.querySelector("body");
269
+ if (mode === "dark") {
270
+ bodyEl.classList.add("quarto-dark");
271
+ bodyEl.classList.remove("quarto-light");
272
+ } else {
273
+ bodyEl.classList.add("quarto-light");
274
+ bodyEl.classList.remove("quarto-dark");
275
+ }
276
+ }
277
+ const toggleBodyColorPrimary = () => {
278
+ const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
279
+ if (bsSheetEl) {
280
+ toggleBodyColorMode(bsSheetEl);
281
+ }
282
+ }
283
+ toggleBodyColorPrimary();
284
+ const icon = "";
285
+ const anchorJS = new window.AnchorJS();
286
+ anchorJS.options = {
287
+ placement: 'right',
288
+ icon: icon
289
+ };
290
+ anchorJS.add('.anchored');
291
+ const isCodeAnnotation = (el) => {
292
+ for (const clz of el.classList) {
293
+ if (clz.startsWith('code-annotation-')) {
294
+ return true;
295
+ }
296
+ }
297
+ return false;
298
+ }
299
+ const onCopySuccess = function(e) {
300
+ // button target
301
+ const button = e.trigger;
302
+ // don't keep focus
303
+ button.blur();
304
+ // flash "checked"
305
+ button.classList.add('code-copy-button-checked');
306
+ var currentTitle = button.getAttribute("title");
307
+ button.setAttribute("title", "Copied!");
308
+ let tooltip;
309
+ if (window.bootstrap) {
310
+ button.setAttribute("data-bs-toggle", "tooltip");
311
+ button.setAttribute("data-bs-placement", "left");
312
+ button.setAttribute("data-bs-title", "Copied!");
313
+ tooltip = new bootstrap.Tooltip(button,
314
+ { trigger: "manual",
315
+ customClass: "code-copy-button-tooltip",
316
+ offset: [0, -8]});
317
+ tooltip.show();
318
+ }
319
+ setTimeout(function() {
320
+ if (tooltip) {
321
+ tooltip.hide();
322
+ button.removeAttribute("data-bs-title");
323
+ button.removeAttribute("data-bs-toggle");
324
+ button.removeAttribute("data-bs-placement");
325
+ }
326
+ button.setAttribute("title", currentTitle);
327
+ button.classList.remove('code-copy-button-checked');
328
+ }, 1000);
329
+ // clear code selection
330
+ e.clearSelection();
331
+ }
332
+ const getTextToCopy = function(trigger) {
333
+ const codeEl = trigger.previousElementSibling.cloneNode(true);
334
+ for (const childEl of codeEl.children) {
335
+ if (isCodeAnnotation(childEl)) {
336
+ childEl.remove();
337
+ }
338
+ }
339
+ return codeEl.innerText;
340
+ }
341
+ const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
342
+ text: getTextToCopy
343
+ });
344
+ clipboard.on('success', onCopySuccess);
345
+ if (window.document.getElementById('quarto-embedded-source-code-modal')) {
346
+ // For code content inside modals, clipBoardJS needs to be initialized with a container option
347
+ // TODO: Check when it could be a function (https://github.com/zenorocha/clipboard.js/issues/860)
348
+ const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
349
+ text: getTextToCopy,
350
+ container: window.document.getElementById('quarto-embedded-source-code-modal')
351
+ });
352
+ clipboardModal.on('success', onCopySuccess);
353
+ }
354
+ var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
355
+ var mailtoRegex = new RegExp(/^mailto:/);
356
+ var filterRegex = new RegExp("https:\/\/huggingface\.co\/spaces\/aephidayatuloh\/codewarschallenge\/");
357
+ var isInternal = (href) => {
358
+ return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
359
+ }
360
+ // Inspect non-navigation links and adorn them if external
361
+ var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
362
+ for (var i=0; i<links.length; i++) {
363
+ const link = links[i];
364
+ if (!isInternal(link.href)) {
365
+ // undo the damage that might have been done by quarto-nav.js in the case of
366
+ // links that we want to consider external
367
+ if (link.dataset.originalHref !== undefined) {
368
+ link.href = link.dataset.originalHref;
369
+ }
370
+ }
371
+ }
372
+ function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
373
+ const config = {
374
+ allowHTML: true,
375
+ maxWidth: 500,
376
+ delay: 100,
377
+ arrow: false,
378
+ appendTo: function(el) {
379
+ return el.parentElement;
380
+ },
381
+ interactive: true,
382
+ interactiveBorder: 10,
383
+ theme: 'quarto',
384
+ placement: 'bottom-start',
385
+ };
386
+ if (contentFn) {
387
+ config.content = contentFn;
388
+ }
389
+ if (onTriggerFn) {
390
+ config.onTrigger = onTriggerFn;
391
+ }
392
+ if (onUntriggerFn) {
393
+ config.onUntrigger = onUntriggerFn;
394
+ }
395
+ window.tippy(el, config);
396
+ }
397
+ const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
398
+ for (var i=0; i<noterefs.length; i++) {
399
+ const ref = noterefs[i];
400
+ tippyHover(ref, function() {
401
+ // use id or data attribute instead here
402
+ let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
403
+ try { href = new URL(href).hash; } catch {}
404
+ const id = href.replace(/^#\/?/, "");
405
+ const note = window.document.getElementById(id);
406
+ if (note) {
407
+ return note.innerHTML;
408
+ } else {
409
+ return "";
410
+ }
411
+ });
412
+ }
413
+ const xrefs = window.document.querySelectorAll('a.quarto-xref');
414
+ const processXRef = (id, note) => {
415
+ // Strip column container classes
416
+ const stripColumnClz = (el) => {
417
+ el.classList.remove("page-full", "page-columns");
418
+ if (el.children) {
419
+ for (const child of el.children) {
420
+ stripColumnClz(child);
421
+ }
422
+ }
423
+ }
424
+ stripColumnClz(note)
425
+ if (id === null || id.startsWith('sec-')) {
426
+ // Special case sections, only their first couple elements
427
+ const container = document.createElement("div");
428
+ if (note.children && note.children.length > 2) {
429
+ container.appendChild(note.children[0].cloneNode(true));
430
+ for (let i = 1; i < note.children.length; i++) {
431
+ const child = note.children[i];
432
+ if (child.tagName === "P" && child.innerText === "") {
433
+ continue;
434
+ } else {
435
+ container.appendChild(child.cloneNode(true));
436
+ break;
437
+ }
438
+ }
439
+ if (window.Quarto?.typesetMath) {
440
+ window.Quarto.typesetMath(container);
441
+ }
442
+ return container.innerHTML
443
+ } else {
444
+ if (window.Quarto?.typesetMath) {
445
+ window.Quarto.typesetMath(note);
446
+ }
447
+ return note.innerHTML;
448
+ }
449
+ } else {
450
+ // Remove any anchor links if they are present
451
+ const anchorLink = note.querySelector('a.anchorjs-link');
452
+ if (anchorLink) {
453
+ anchorLink.remove();
454
+ }
455
+ if (window.Quarto?.typesetMath) {
456
+ window.Quarto.typesetMath(note);
457
+ }
458
+ // TODO in 1.5, we should make sure this works without a callout special case
459
+ if (note.classList.contains("callout")) {
460
+ return note.outerHTML;
461
+ } else {
462
+ return note.innerHTML;
463
+ }
464
+ }
465
+ }
466
+ for (var i=0; i<xrefs.length; i++) {
467
+ const xref = xrefs[i];
468
+ tippyHover(xref, undefined, function(instance) {
469
+ instance.disable();
470
+ let url = xref.getAttribute('href');
471
+ let hash = undefined;
472
+ if (url.startsWith('#')) {
473
+ hash = url;
474
+ } else {
475
+ try { hash = new URL(url).hash; } catch {}
476
+ }
477
+ if (hash) {
478
+ const id = hash.replace(/^#\/?/, "");
479
+ const note = window.document.getElementById(id);
480
+ if (note !== null) {
481
+ try {
482
+ const html = processXRef(id, note.cloneNode(true));
483
+ instance.setContent(html);
484
+ } finally {
485
+ instance.enable();
486
+ instance.show();
487
+ }
488
+ } else {
489
+ // See if we can fetch this
490
+ fetch(url.split('#')[0])
491
+ .then(res => res.text())
492
+ .then(html => {
493
+ const parser = new DOMParser();
494
+ const htmlDoc = parser.parseFromString(html, "text/html");
495
+ const note = htmlDoc.getElementById(id);
496
+ if (note !== null) {
497
+ const html = processXRef(id, note);
498
+ instance.setContent(html);
499
+ }
500
+ }).finally(() => {
501
+ instance.enable();
502
+ instance.show();
503
+ });
504
+ }
505
+ } else {
506
+ // See if we can fetch a full url (with no hash to target)
507
+ // This is a special case and we should probably do some content thinning / targeting
508
+ fetch(url)
509
+ .then(res => res.text())
510
+ .then(html => {
511
+ const parser = new DOMParser();
512
+ const htmlDoc = parser.parseFromString(html, "text/html");
513
+ const note = htmlDoc.querySelector('main.content');
514
+ if (note !== null) {
515
+ // This should only happen for chapter cross references
516
+ // (since there is no id in the URL)
517
+ // remove the first header
518
+ if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
519
+ note.children[0].remove();
520
+ }
521
+ const html = processXRef(null, note);
522
+ instance.setContent(html);
523
+ }
524
+ }).finally(() => {
525
+ instance.enable();
526
+ instance.show();
527
+ });
528
+ }
529
+ }, function(instance) {
530
+ });
531
+ }
532
+ let selectedAnnoteEl;
533
+ const selectorForAnnotation = ( cell, annotation) => {
534
+ let cellAttr = 'data-code-cell="' + cell + '"';
535
+ let lineAttr = 'data-code-annotation="' + annotation + '"';
536
+ const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
537
+ return selector;
538
+ }
539
+ const selectCodeLines = (annoteEl) => {
540
+ const doc = window.document;
541
+ const targetCell = annoteEl.getAttribute("data-target-cell");
542
+ const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
543
+ const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
544
+ const lines = annoteSpan.getAttribute("data-code-lines").split(",");
545
+ const lineIds = lines.map((line) => {
546
+ return targetCell + "-" + line;
547
+ })
548
+ let top = null;
549
+ let height = null;
550
+ let parent = null;
551
+ if (lineIds.length > 0) {
552
+ //compute the position of the single el (top and bottom and make a div)
553
+ const el = window.document.getElementById(lineIds[0]);
554
+ top = el.offsetTop;
555
+ height = el.offsetHeight;
556
+ parent = el.parentElement.parentElement;
557
+ if (lineIds.length > 1) {
558
+ const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
559
+ const bottom = lastEl.offsetTop + lastEl.offsetHeight;
560
+ height = bottom - top;
561
+ }
562
+ if (top !== null && height !== null && parent !== null) {
563
+ // cook up a div (if necessary) and position it
564
+ let div = window.document.getElementById("code-annotation-line-highlight");
565
+ if (div === null) {
566
+ div = window.document.createElement("div");
567
+ div.setAttribute("id", "code-annotation-line-highlight");
568
+ div.style.position = 'absolute';
569
+ parent.appendChild(div);
570
+ }
571
+ div.style.top = top - 2 + "px";
572
+ div.style.height = height + 4 + "px";
573
+ div.style.left = 0;
574
+ let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
575
+ if (gutterDiv === null) {
576
+ gutterDiv = window.document.createElement("div");
577
+ gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
578
+ gutterDiv.style.position = 'absolute';
579
+ const codeCell = window.document.getElementById(targetCell);
580
+ const gutter = codeCell.querySelector('.code-annotation-gutter');
581
+ gutter.appendChild(gutterDiv);
582
+ }
583
+ gutterDiv.style.top = top - 2 + "px";
584
+ gutterDiv.style.height = height + 4 + "px";
585
+ }
586
+ selectedAnnoteEl = annoteEl;
587
+ }
588
+ };
589
+ const unselectCodeLines = () => {
590
+ const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
591
+ elementsIds.forEach((elId) => {
592
+ const div = window.document.getElementById(elId);
593
+ if (div) {
594
+ div.remove();
595
+ }
596
+ });
597
+ selectedAnnoteEl = undefined;
598
+ };
599
+ // Handle positioning of the toggle
600
+ window.addEventListener(
601
+ "resize",
602
+ throttle(() => {
603
+ elRect = undefined;
604
+ if (selectedAnnoteEl) {
605
+ selectCodeLines(selectedAnnoteEl);
606
+ }
607
+ }, 10)
608
+ );
609
+ function throttle(fn, ms) {
610
+ let throttle = false;
611
+ let timer;
612
+ return (...args) => {
613
+ if(!throttle) { // first call gets through
614
+ fn.apply(this, args);
615
+ throttle = true;
616
+ } else { // all the others get throttled
617
+ if(timer) clearTimeout(timer); // cancel #2
618
+ timer = setTimeout(() => {
619
+ fn.apply(this, args);
620
+ timer = throttle = false;
621
+ }, ms);
622
+ }
623
+ };
624
+ }
625
+ // Attach click handler to the DT
626
+ const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
627
+ for (const annoteDlNode of annoteDls) {
628
+ annoteDlNode.addEventListener('click', (event) => {
629
+ const clickedEl = event.target;
630
+ if (clickedEl !== selectedAnnoteEl) {
631
+ unselectCodeLines();
632
+ const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
633
+ if (activeEl) {
634
+ activeEl.classList.remove('code-annotation-active');
635
+ }
636
+ selectCodeLines(clickedEl);
637
+ clickedEl.classList.add('code-annotation-active');
638
+ } else {
639
+ // Unselect the line
640
+ unselectCodeLines();
641
+ clickedEl.classList.remove('code-annotation-active');
642
+ }
643
+ });
644
+ }
645
+ const findCites = (el) => {
646
+ const parentEl = el.parentElement;
647
+ if (parentEl) {
648
+ const cites = parentEl.dataset.cites;
649
+ if (cites) {
650
+ return {
651
+ el,
652
+ cites: cites.split(' ')
653
+ };
654
+ } else {
655
+ return findCites(el.parentElement)
656
+ }
657
+ } else {
658
+ return undefined;
659
+ }
660
+ };
661
+ var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
662
+ for (var i=0; i<bibliorefs.length; i++) {
663
+ const ref = bibliorefs[i];
664
+ const citeInfo = findCites(ref);
665
+ if (citeInfo) {
666
+ tippyHover(citeInfo.el, function() {
667
+ var popup = window.document.createElement('div');
668
+ citeInfo.cites.forEach(function(cite) {
669
+ var citeDiv = window.document.createElement('div');
670
+ citeDiv.classList.add('hanging-indent');
671
+ citeDiv.classList.add('csl-entry');
672
+ var biblioDiv = window.document.getElementById('ref-' + cite);
673
+ if (biblioDiv) {
674
+ citeDiv.innerHTML = biblioDiv.innerHTML;
675
+ }
676
+ popup.appendChild(citeDiv);
677
+ });
678
+ return popup.innerHTML;
679
+ });
680
+ }
681
+ }
682
+ });
683
+ </script><nav class="page-navigation"><div class="nav-page nav-page-previous">
684
+ <a href="./cw0001evenodd.html" class="pagination-link" aria-label="Even or Odd">
685
+ <i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span></span>
686
+ </a>
687
+ </div>
688
+ <div class="nav-page nav-page-next">
689
+ <a href="./cw0003countsheep.html" class="pagination-link" aria-label="Count Sheep">
690
+ <span class="nav-page-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Count Sheep</span></span> <i class="bi bi-arrow-right-short"></i>
691
+ </a>
692
+ </div>
693
+ </nav>
694
+ </div> <!-- /content -->
695
+
696
+
697
+
698
+ </body></html>
cw0003countsheep.html ADDED
@@ -0,0 +1,704 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
3
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4
+ <meta charset="utf-8">
5
+ <meta name="generator" content="quarto-1.5.53">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
7
+ <title>3&nbsp; If you can’t sleep, just count sheep!! – Codewars Challenge</title>
8
+ <style>
9
+ code{white-space: pre-wrap;}
10
+ span.smallcaps{font-variant: small-caps;}
11
+ div.columns{display: flex; gap: min(4vw, 1.5em);}
12
+ div.column{flex: auto; overflow-x: auto;}
13
+ div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
14
+ ul.task-list{list-style: none;}
15
+ ul.task-list li input[type="checkbox"] {
16
+ width: 0.8em;
17
+ margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
18
+ vertical-align: middle;
19
+ }
20
+ /* CSS for syntax highlighting */
21
+ pre > code.sourceCode { white-space: pre; position: relative; }
22
+ pre > code.sourceCode > span { line-height: 1.25; }
23
+ pre > code.sourceCode > span:empty { height: 1.2em; }
24
+ .sourceCode { overflow: visible; }
25
+ code.sourceCode > span { color: inherit; text-decoration: inherit; }
26
+ div.sourceCode { margin: 1em 0; }
27
+ pre.sourceCode { margin: 0; }
28
+ @media screen {
29
+ div.sourceCode { overflow: auto; }
30
+ }
31
+ @media print {
32
+ pre > code.sourceCode { white-space: pre-wrap; }
33
+ pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
34
+ }
35
+ pre.numberSource code
36
+ { counter-reset: source-line 0; }
37
+ pre.numberSource code > span
38
+ { position: relative; left: -4em; counter-increment: source-line; }
39
+ pre.numberSource code > span > a:first-child::before
40
+ { content: counter(source-line);
41
+ position: relative; left: -1em; text-align: right; vertical-align: baseline;
42
+ border: none; display: inline-block;
43
+ -webkit-touch-callout: none; -webkit-user-select: none;
44
+ -khtml-user-select: none; -moz-user-select: none;
45
+ -ms-user-select: none; user-select: none;
46
+ padding: 0 4px; width: 4em;
47
+ }
48
+ pre.numberSource { margin-left: 3em; padding-left: 4px; }
49
+ div.sourceCode
50
+ { }
51
+ @media screen {
52
+ pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
53
+ }
54
+ </style>
55
+
56
+ <script src="site_libs/quarto-nav/quarto-nav.js"></script>
57
+ <script src="site_libs/quarto-nav/headroom.min.js"></script>
58
+ <script src="site_libs/clipboard/clipboard.min.js"></script>
59
+ <script src="site_libs/quarto-search/autocomplete.umd.js"></script>
60
+ <script src="site_libs/quarto-search/fuse.min.js"></script>
61
+ <script src="site_libs/quarto-search/quarto-search.js"></script>
62
+ <meta name="quarto:offset" content="./">
63
+ <link href="./cw0004reducegrow.html" rel="next">
64
+ <link href="./cw0002multiply.html" rel="prev">
65
+ <script src="site_libs/quarto-html/quarto.js"></script>
66
+ <script src="site_libs/quarto-html/popper.min.js"></script>
67
+ <script src="site_libs/quarto-html/tippy.umd.min.js"></script>
68
+ <script src="site_libs/quarto-html/anchor.min.js"></script>
69
+ <link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
70
+ <link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
71
+ <script src="site_libs/bootstrap/bootstrap.min.js"></script>
72
+ <link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
73
+ <link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light"><script id="quarto-search-options" type="application/json">{
74
+ "location": "sidebar",
75
+ "copy-button": false,
76
+ "collapse-after": 3,
77
+ "panel-placement": "start",
78
+ "type": "textbox",
79
+ "limit": 50,
80
+ "keyboard-shortcut": [
81
+ "f",
82
+ "/",
83
+ "s"
84
+ ],
85
+ "show-item-context": false,
86
+ "language": {
87
+ "search-no-results-text": "No results",
88
+ "search-matching-documents-text": "matching documents",
89
+ "search-copy-link-title": "Copy link to search",
90
+ "search-hide-matches-text": "Hide additional matches",
91
+ "search-more-match-text": "more match in this document",
92
+ "search-more-matches-text": "more matches in this document",
93
+ "search-clear-button-title": "Clear",
94
+ "search-text-placeholder": "",
95
+ "search-detached-cancel-button-title": "Cancel",
96
+ "search-submit-button-title": "Submit",
97
+ "search-label": "Search"
98
+ }
99
+ }</script><link rel="stylesheet" href="style.css">
100
+ <meta name="twitter:title" content="3&nbsp; If you can’t sleep, just count sheep!! – Codewars Challenge">
101
+ <meta name="twitter:description" content="">
102
+ <meta name="twitter:card" content="summary">
103
+ </head>
104
+ <body class="nav-sidebar floating">
105
+
106
+ <div id="quarto-search-results"></div>
107
+ <header id="quarto-header" class="headroom fixed-top"><nav class="quarto-secondary-nav"><div class="container-fluid d-flex">
108
+ <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" role="button" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
109
+ <i class="bi bi-layout-text-sidebar-reverse"></i>
110
+ </button>
111
+ <nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./cw0001evenodd.html">2025</a></li><li class="breadcrumb-item"><a href="./cw0003countsheep.html"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Count Sheep</span></a></li></ol></nav>
112
+ <a class="flex-grow-1" role="navigation" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
113
+ </a>
114
+ <button type="button" class="btn quarto-search-button" aria-label="Search" onclick="window.quartoOpenSearch();">
115
+ <i class="bi bi-search"></i>
116
+ </button>
117
+ </div>
118
+ </nav></header><!-- content --><div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
119
+ <!-- sidebar -->
120
+ <nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal quarto-sidebar-collapse-item sidebar-navigation floating overflow-auto"><div class="pt-lg-2 mt-2 text-left sidebar-header">
121
+ <div class="sidebar-title mb-0 py-0">
122
+ <a href="./">Codewars Challenge</a>
123
+ <div class="sidebar-tools-main">
124
+ <a href="https://huggingface.co/spaces/aephidayatuloh/codewarschallenge/tree/main" title="Source Code" class="quarto-navigation-tool px-1" aria-label="Source Code"><i class="bi bi-git"></i></a>
125
+ </div>
126
+ </div>
127
+ </div>
128
+ <div class="mt-2 flex-shrink-0 align-items-center">
129
+ <div class="sidebar-search">
130
+ <div id="quarto-search" class="" title="Search"></div>
131
+ </div>
132
+ </div>
133
+ <div class="sidebar-menu-container">
134
+ <ul class="list-unstyled mt-1">
135
+ <li class="sidebar-item">
136
+ <div class="sidebar-item-container">
137
+ <a href="./index.html" class="sidebar-item-text sidebar-link">
138
+ <span class="menu-text">Pengantar</span></a>
139
+ </div>
140
+ </li>
141
+ <li class="sidebar-item sidebar-item-section">
142
+ <div class="sidebar-item-container">
143
+ <a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true">
144
+ <span class="menu-text">2025</span></a>
145
+ <a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true" aria-label="Toggle section">
146
+ <i class="bi bi-chevron-right ms-2"></i>
147
+ </a>
148
+ </div>
149
+ <ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
150
+ <li class="sidebar-item">
151
+ <div class="sidebar-item-container">
152
+ <a href="./cw0001evenodd.html" class="sidebar-item-text sidebar-link">
153
+ <span class="menu-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span></span></a>
154
+ </div>
155
+ </li>
156
+ <li class="sidebar-item">
157
+ <div class="sidebar-item-container">
158
+ <a href="./cw0002multiply.html" class="sidebar-item-text sidebar-link">
159
+ <span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span></span></a>
160
+ </div>
161
+ </li>
162
+ <li class="sidebar-item">
163
+ <div class="sidebar-item-container">
164
+ <a href="./cw0003countsheep.html" class="sidebar-item-text sidebar-link active">
165
+ <span class="menu-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Count Sheep</span></span></a>
166
+ </div>
167
+ </li>
168
+ <li class="sidebar-item">
169
+ <div class="sidebar-item-container">
170
+ <a href="./cw0004reducegrow.html" class="sidebar-item-text sidebar-link">
171
+ <span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow!</span></span></a>
172
+ </div>
173
+ </li>
174
+ <li class="sidebar-item">
175
+ <div class="sidebar-item-container">
176
+ <a href="./cw0005makenegative.html" class="sidebar-item-text sidebar-link">
177
+ <span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Return Negative</span></span></a>
178
+ </div>
179
+ </li>
180
+ </ul>
181
+ </li>
182
+ </ul>
183
+ </div>
184
+ </nav><div id="quarto-sidebar-glass" class="quarto-sidebar-collapse-item" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item"></div>
185
+ <!-- margin-sidebar -->
186
+ <div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
187
+ <nav id="TOC" role="doc-toc" class="toc-active" data-toc-expanded="99"><h2 id="toc-title">Table of contents</h2>
188
+
189
+ <ul>
190
+ <li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">3.1</span> Instruction</a></li>
191
+ <li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">3.2</span> YouTube Video</a></li>
192
+ <li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">3.3</span> Solution Code</a></li>
193
+ <li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">3.4</span> Test</a></li>
194
+ </ul></nav>
195
+ </div>
196
+ <!-- main -->
197
+ <main class="content" id="quarto-document-content"><header id="title-block-header" class="quarto-title-block default"><nav class="quarto-page-breadcrumbs quarto-title-breadcrumbs d-none d-lg-block" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./cw0001evenodd.html">2025</a></li><li class="breadcrumb-item"><a href="./cw0003countsheep.html"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Count Sheep</span></a></li></ol></nav><div class="quarto-title">
198
+ <h1 class="title">
199
+ <span class="chapter-number">3</span>&nbsp; <span class="chapter-title">If you can’t sleep, just count sheep!!</span>
200
+ </h1>
201
+ </div>
202
+
203
+
204
+
205
+ <div class="quarto-title-meta">
206
+
207
+
208
+
209
+
210
+ </div>
211
+
212
+
213
+
214
+ </header><p><span class="badge rounded-pill quarto-badge">8Kyu</span> Tantangan #3/366 - 03 Feb 2025</p>
215
+ <p><a href="https://www.codewars.com/kata/5b077ebdaf15be5c7f000077" class="uri">https://www.codewars.com/kata/5b077ebdaf15be5c7f000077</a></p>
216
+ <h2 data-number="3.1" id="instruction" class="anchored">
217
+ <span class="header-section-number">3.1</span> Instruction</h2>
218
+ <blockquote class="blockquote">
219
+ <p>Given a non-negative integer, <code>3</code> for example, return a string with a murmur: <code>"1 sheep…2 sheep…3 sheep…"</code>. Input will always be valid, i.e.&nbsp;no negative integers.</p>
220
+ </blockquote>
221
+ <h2 data-number="3.2" id="youtube-video" class="anchored">
222
+ <span class="header-section-number">3.2</span> YouTube Video</h2>
223
+ <div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/L8aczEhqymk" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
224
+ <h2 data-number="3.3" id="solution-code" class="anchored">
225
+ <span class="header-section-number">3.3</span> Solution Code</h2>
226
+ <p>Solusi bar-bar</p>
227
+ <div class="cell">
228
+ <div class="sourceCode" id="cb1"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">countSheep</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">num</span><span class="op">)</span><span class="op">{</span></span>
229
+ <span> <span class="kw">if</span><span class="op">(</span><span class="va">num</span> <span class="op">==</span> <span class="fl">0</span><span class="op">)</span><span class="op">{</span></span>
230
+ <span> <span class="kw"><a href="https://rdrr.io/r/base/function.html">return</a></span><span class="op">(</span><span class="st">""</span><span class="op">)</span></span>
231
+ <span> <span class="op">}</span> <span class="kw">else</span> <span class="op">{</span></span>
232
+ <span> <span class="va">result</span> <span class="op">&lt;-</span> <span class="st">""</span></span>
233
+ <span> <span class="kw">for</span><span class="op">(</span><span class="va">i</span> <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="va">num</span><span class="op">)</span><span class="op">{</span></span>
234
+ <span> <span class="va">result</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste</a></span><span class="op">(</span><span class="va">result</span>, <span class="va">i</span>, <span class="st">" sheep..."</span>, sep <span class="op">=</span> <span class="st">""</span><span class="op">)</span></span>
235
+ <span> <span class="op">}</span></span>
236
+ <span> <span class="kw"><a href="https://rdrr.io/r/base/function.html">return</a></span><span class="op">(</span><span class="va">result</span><span class="op">)</span></span>
237
+ <span> <span class="op">}</span></span>
238
+ <span><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
239
+ </div>
240
+ <p>Solusi simple</p>
241
+ <div class="cell">
242
+ <div class="sourceCode" id="cb2"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">countSheep</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">num</span><span class="op">)</span><span class="op">{</span></span>
243
+ <span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op">(</span><span class="va">num</span> <span class="op">==</span> <span class="fl">0</span>, <span class="st">""</span>, <span class="fu"><a href="https://rdrr.io/r/base/paste.html">paste</a></span><span class="op">(</span><span class="fl">1</span><span class="op">:</span><span class="va">num</span>, <span class="st">"sheep..."</span>, collapse <span class="op">=</span> <span class="st">""</span><span class="op">)</span><span class="op">)</span></span>
244
+ <span><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
245
+ </div>
246
+ <h2 data-number="3.4" id="test" class="anchored">
247
+ <span class="header-section-number">3.4</span> Test</h2>
248
+ <div class="cell">
249
+ <div class="sourceCode" id="cb3"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://testthat.r-lib.org">testthat</a></span><span class="op">)</span></span>
250
+ <span></span>
251
+ <span><span class="fu"><a href="https://testthat.r-lib.org/reference/test_that.html">test_that</a></span><span class="op">(</span><span class="st">"Fixed tests"</span>, <span class="op">{</span></span>
252
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">countSheep</span><span class="op">(</span><span class="fl">0</span><span class="op">)</span>, <span class="st">""</span><span class="op">)</span></span>
253
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">countSheep</span><span class="op">(</span><span class="fl">1</span><span class="op">)</span>, <span class="st">"1 sheep..."</span><span class="op">)</span></span>
254
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">countSheep</span><span class="op">(</span><span class="fl">2</span><span class="op">)</span>, <span class="st">"1 sheep...2 sheep..."</span><span class="op">)</span></span>
255
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">countSheep</span><span class="op">(</span><span class="fl">3</span><span class="op">)</span>, <span class="st">"1 sheep...2 sheep...3 sheep..."</span><span class="op">)</span></span>
256
+ <span><span class="op">}</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
257
+ <div class="cell-output cell-output-stdout">
258
+ <pre><code>## Test passed 🥳</code></pre>
259
+ </div>
260
+ </div>
261
+ <hr>
262
+ <p><strong>Supported by</strong></p>
263
+ <div class="quarto-figure quarto-figure-center">
264
+ <figure class="figure"><p><img src="new_starcore_logo.png" class="img-fluid figure-img"></p>
265
+ <figcaption>StarCore Analytics</figcaption></figure>
266
+ </div>
267
+
268
+
269
+
270
+ </main><!-- /main --><script id="quarto-html-after-body" type="application/javascript">
271
+ window.document.addEventListener("DOMContentLoaded", function (event) {
272
+ const toggleBodyColorMode = (bsSheetEl) => {
273
+ const mode = bsSheetEl.getAttribute("data-mode");
274
+ const bodyEl = window.document.querySelector("body");
275
+ if (mode === "dark") {
276
+ bodyEl.classList.add("quarto-dark");
277
+ bodyEl.classList.remove("quarto-light");
278
+ } else {
279
+ bodyEl.classList.add("quarto-light");
280
+ bodyEl.classList.remove("quarto-dark");
281
+ }
282
+ }
283
+ const toggleBodyColorPrimary = () => {
284
+ const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
285
+ if (bsSheetEl) {
286
+ toggleBodyColorMode(bsSheetEl);
287
+ }
288
+ }
289
+ toggleBodyColorPrimary();
290
+ const icon = "";
291
+ const anchorJS = new window.AnchorJS();
292
+ anchorJS.options = {
293
+ placement: 'right',
294
+ icon: icon
295
+ };
296
+ anchorJS.add('.anchored');
297
+ const isCodeAnnotation = (el) => {
298
+ for (const clz of el.classList) {
299
+ if (clz.startsWith('code-annotation-')) {
300
+ return true;
301
+ }
302
+ }
303
+ return false;
304
+ }
305
+ const onCopySuccess = function(e) {
306
+ // button target
307
+ const button = e.trigger;
308
+ // don't keep focus
309
+ button.blur();
310
+ // flash "checked"
311
+ button.classList.add('code-copy-button-checked');
312
+ var currentTitle = button.getAttribute("title");
313
+ button.setAttribute("title", "Copied!");
314
+ let tooltip;
315
+ if (window.bootstrap) {
316
+ button.setAttribute("data-bs-toggle", "tooltip");
317
+ button.setAttribute("data-bs-placement", "left");
318
+ button.setAttribute("data-bs-title", "Copied!");
319
+ tooltip = new bootstrap.Tooltip(button,
320
+ { trigger: "manual",
321
+ customClass: "code-copy-button-tooltip",
322
+ offset: [0, -8]});
323
+ tooltip.show();
324
+ }
325
+ setTimeout(function() {
326
+ if (tooltip) {
327
+ tooltip.hide();
328
+ button.removeAttribute("data-bs-title");
329
+ button.removeAttribute("data-bs-toggle");
330
+ button.removeAttribute("data-bs-placement");
331
+ }
332
+ button.setAttribute("title", currentTitle);
333
+ button.classList.remove('code-copy-button-checked');
334
+ }, 1000);
335
+ // clear code selection
336
+ e.clearSelection();
337
+ }
338
+ const getTextToCopy = function(trigger) {
339
+ const codeEl = trigger.previousElementSibling.cloneNode(true);
340
+ for (const childEl of codeEl.children) {
341
+ if (isCodeAnnotation(childEl)) {
342
+ childEl.remove();
343
+ }
344
+ }
345
+ return codeEl.innerText;
346
+ }
347
+ const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
348
+ text: getTextToCopy
349
+ });
350
+ clipboard.on('success', onCopySuccess);
351
+ if (window.document.getElementById('quarto-embedded-source-code-modal')) {
352
+ // For code content inside modals, clipBoardJS needs to be initialized with a container option
353
+ // TODO: Check when it could be a function (https://github.com/zenorocha/clipboard.js/issues/860)
354
+ const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
355
+ text: getTextToCopy,
356
+ container: window.document.getElementById('quarto-embedded-source-code-modal')
357
+ });
358
+ clipboardModal.on('success', onCopySuccess);
359
+ }
360
+ var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
361
+ var mailtoRegex = new RegExp(/^mailto:/);
362
+ var filterRegex = new RegExp("https:\/\/huggingface\.co\/spaces\/aephidayatuloh\/codewarschallenge\/");
363
+ var isInternal = (href) => {
364
+ return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
365
+ }
366
+ // Inspect non-navigation links and adorn them if external
367
+ var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
368
+ for (var i=0; i<links.length; i++) {
369
+ const link = links[i];
370
+ if (!isInternal(link.href)) {
371
+ // undo the damage that might have been done by quarto-nav.js in the case of
372
+ // links that we want to consider external
373
+ if (link.dataset.originalHref !== undefined) {
374
+ link.href = link.dataset.originalHref;
375
+ }
376
+ }
377
+ }
378
+ function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
379
+ const config = {
380
+ allowHTML: true,
381
+ maxWidth: 500,
382
+ delay: 100,
383
+ arrow: false,
384
+ appendTo: function(el) {
385
+ return el.parentElement;
386
+ },
387
+ interactive: true,
388
+ interactiveBorder: 10,
389
+ theme: 'quarto',
390
+ placement: 'bottom-start',
391
+ };
392
+ if (contentFn) {
393
+ config.content = contentFn;
394
+ }
395
+ if (onTriggerFn) {
396
+ config.onTrigger = onTriggerFn;
397
+ }
398
+ if (onUntriggerFn) {
399
+ config.onUntrigger = onUntriggerFn;
400
+ }
401
+ window.tippy(el, config);
402
+ }
403
+ const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
404
+ for (var i=0; i<noterefs.length; i++) {
405
+ const ref = noterefs[i];
406
+ tippyHover(ref, function() {
407
+ // use id or data attribute instead here
408
+ let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
409
+ try { href = new URL(href).hash; } catch {}
410
+ const id = href.replace(/^#\/?/, "");
411
+ const note = window.document.getElementById(id);
412
+ if (note) {
413
+ return note.innerHTML;
414
+ } else {
415
+ return "";
416
+ }
417
+ });
418
+ }
419
+ const xrefs = window.document.querySelectorAll('a.quarto-xref');
420
+ const processXRef = (id, note) => {
421
+ // Strip column container classes
422
+ const stripColumnClz = (el) => {
423
+ el.classList.remove("page-full", "page-columns");
424
+ if (el.children) {
425
+ for (const child of el.children) {
426
+ stripColumnClz(child);
427
+ }
428
+ }
429
+ }
430
+ stripColumnClz(note)
431
+ if (id === null || id.startsWith('sec-')) {
432
+ // Special case sections, only their first couple elements
433
+ const container = document.createElement("div");
434
+ if (note.children && note.children.length > 2) {
435
+ container.appendChild(note.children[0].cloneNode(true));
436
+ for (let i = 1; i < note.children.length; i++) {
437
+ const child = note.children[i];
438
+ if (child.tagName === "P" && child.innerText === "") {
439
+ continue;
440
+ } else {
441
+ container.appendChild(child.cloneNode(true));
442
+ break;
443
+ }
444
+ }
445
+ if (window.Quarto?.typesetMath) {
446
+ window.Quarto.typesetMath(container);
447
+ }
448
+ return container.innerHTML
449
+ } else {
450
+ if (window.Quarto?.typesetMath) {
451
+ window.Quarto.typesetMath(note);
452
+ }
453
+ return note.innerHTML;
454
+ }
455
+ } else {
456
+ // Remove any anchor links if they are present
457
+ const anchorLink = note.querySelector('a.anchorjs-link');
458
+ if (anchorLink) {
459
+ anchorLink.remove();
460
+ }
461
+ if (window.Quarto?.typesetMath) {
462
+ window.Quarto.typesetMath(note);
463
+ }
464
+ // TODO in 1.5, we should make sure this works without a callout special case
465
+ if (note.classList.contains("callout")) {
466
+ return note.outerHTML;
467
+ } else {
468
+ return note.innerHTML;
469
+ }
470
+ }
471
+ }
472
+ for (var i=0; i<xrefs.length; i++) {
473
+ const xref = xrefs[i];
474
+ tippyHover(xref, undefined, function(instance) {
475
+ instance.disable();
476
+ let url = xref.getAttribute('href');
477
+ let hash = undefined;
478
+ if (url.startsWith('#')) {
479
+ hash = url;
480
+ } else {
481
+ try { hash = new URL(url).hash; } catch {}
482
+ }
483
+ if (hash) {
484
+ const id = hash.replace(/^#\/?/, "");
485
+ const note = window.document.getElementById(id);
486
+ if (note !== null) {
487
+ try {
488
+ const html = processXRef(id, note.cloneNode(true));
489
+ instance.setContent(html);
490
+ } finally {
491
+ instance.enable();
492
+ instance.show();
493
+ }
494
+ } else {
495
+ // See if we can fetch this
496
+ fetch(url.split('#')[0])
497
+ .then(res => res.text())
498
+ .then(html => {
499
+ const parser = new DOMParser();
500
+ const htmlDoc = parser.parseFromString(html, "text/html");
501
+ const note = htmlDoc.getElementById(id);
502
+ if (note !== null) {
503
+ const html = processXRef(id, note);
504
+ instance.setContent(html);
505
+ }
506
+ }).finally(() => {
507
+ instance.enable();
508
+ instance.show();
509
+ });
510
+ }
511
+ } else {
512
+ // See if we can fetch a full url (with no hash to target)
513
+ // This is a special case and we should probably do some content thinning / targeting
514
+ fetch(url)
515
+ .then(res => res.text())
516
+ .then(html => {
517
+ const parser = new DOMParser();
518
+ const htmlDoc = parser.parseFromString(html, "text/html");
519
+ const note = htmlDoc.querySelector('main.content');
520
+ if (note !== null) {
521
+ // This should only happen for chapter cross references
522
+ // (since there is no id in the URL)
523
+ // remove the first header
524
+ if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
525
+ note.children[0].remove();
526
+ }
527
+ const html = processXRef(null, note);
528
+ instance.setContent(html);
529
+ }
530
+ }).finally(() => {
531
+ instance.enable();
532
+ instance.show();
533
+ });
534
+ }
535
+ }, function(instance) {
536
+ });
537
+ }
538
+ let selectedAnnoteEl;
539
+ const selectorForAnnotation = ( cell, annotation) => {
540
+ let cellAttr = 'data-code-cell="' + cell + '"';
541
+ let lineAttr = 'data-code-annotation="' + annotation + '"';
542
+ const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
543
+ return selector;
544
+ }
545
+ const selectCodeLines = (annoteEl) => {
546
+ const doc = window.document;
547
+ const targetCell = annoteEl.getAttribute("data-target-cell");
548
+ const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
549
+ const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
550
+ const lines = annoteSpan.getAttribute("data-code-lines").split(",");
551
+ const lineIds = lines.map((line) => {
552
+ return targetCell + "-" + line;
553
+ })
554
+ let top = null;
555
+ let height = null;
556
+ let parent = null;
557
+ if (lineIds.length > 0) {
558
+ //compute the position of the single el (top and bottom and make a div)
559
+ const el = window.document.getElementById(lineIds[0]);
560
+ top = el.offsetTop;
561
+ height = el.offsetHeight;
562
+ parent = el.parentElement.parentElement;
563
+ if (lineIds.length > 1) {
564
+ const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
565
+ const bottom = lastEl.offsetTop + lastEl.offsetHeight;
566
+ height = bottom - top;
567
+ }
568
+ if (top !== null && height !== null && parent !== null) {
569
+ // cook up a div (if necessary) and position it
570
+ let div = window.document.getElementById("code-annotation-line-highlight");
571
+ if (div === null) {
572
+ div = window.document.createElement("div");
573
+ div.setAttribute("id", "code-annotation-line-highlight");
574
+ div.style.position = 'absolute';
575
+ parent.appendChild(div);
576
+ }
577
+ div.style.top = top - 2 + "px";
578
+ div.style.height = height + 4 + "px";
579
+ div.style.left = 0;
580
+ let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
581
+ if (gutterDiv === null) {
582
+ gutterDiv = window.document.createElement("div");
583
+ gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
584
+ gutterDiv.style.position = 'absolute';
585
+ const codeCell = window.document.getElementById(targetCell);
586
+ const gutter = codeCell.querySelector('.code-annotation-gutter');
587
+ gutter.appendChild(gutterDiv);
588
+ }
589
+ gutterDiv.style.top = top - 2 + "px";
590
+ gutterDiv.style.height = height + 4 + "px";
591
+ }
592
+ selectedAnnoteEl = annoteEl;
593
+ }
594
+ };
595
+ const unselectCodeLines = () => {
596
+ const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
597
+ elementsIds.forEach((elId) => {
598
+ const div = window.document.getElementById(elId);
599
+ if (div) {
600
+ div.remove();
601
+ }
602
+ });
603
+ selectedAnnoteEl = undefined;
604
+ };
605
+ // Handle positioning of the toggle
606
+ window.addEventListener(
607
+ "resize",
608
+ throttle(() => {
609
+ elRect = undefined;
610
+ if (selectedAnnoteEl) {
611
+ selectCodeLines(selectedAnnoteEl);
612
+ }
613
+ }, 10)
614
+ );
615
+ function throttle(fn, ms) {
616
+ let throttle = false;
617
+ let timer;
618
+ return (...args) => {
619
+ if(!throttle) { // first call gets through
620
+ fn.apply(this, args);
621
+ throttle = true;
622
+ } else { // all the others get throttled
623
+ if(timer) clearTimeout(timer); // cancel #2
624
+ timer = setTimeout(() => {
625
+ fn.apply(this, args);
626
+ timer = throttle = false;
627
+ }, ms);
628
+ }
629
+ };
630
+ }
631
+ // Attach click handler to the DT
632
+ const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
633
+ for (const annoteDlNode of annoteDls) {
634
+ annoteDlNode.addEventListener('click', (event) => {
635
+ const clickedEl = event.target;
636
+ if (clickedEl !== selectedAnnoteEl) {
637
+ unselectCodeLines();
638
+ const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
639
+ if (activeEl) {
640
+ activeEl.classList.remove('code-annotation-active');
641
+ }
642
+ selectCodeLines(clickedEl);
643
+ clickedEl.classList.add('code-annotation-active');
644
+ } else {
645
+ // Unselect the line
646
+ unselectCodeLines();
647
+ clickedEl.classList.remove('code-annotation-active');
648
+ }
649
+ });
650
+ }
651
+ const findCites = (el) => {
652
+ const parentEl = el.parentElement;
653
+ if (parentEl) {
654
+ const cites = parentEl.dataset.cites;
655
+ if (cites) {
656
+ return {
657
+ el,
658
+ cites: cites.split(' ')
659
+ };
660
+ } else {
661
+ return findCites(el.parentElement)
662
+ }
663
+ } else {
664
+ return undefined;
665
+ }
666
+ };
667
+ var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
668
+ for (var i=0; i<bibliorefs.length; i++) {
669
+ const ref = bibliorefs[i];
670
+ const citeInfo = findCites(ref);
671
+ if (citeInfo) {
672
+ tippyHover(citeInfo.el, function() {
673
+ var popup = window.document.createElement('div');
674
+ citeInfo.cites.forEach(function(cite) {
675
+ var citeDiv = window.document.createElement('div');
676
+ citeDiv.classList.add('hanging-indent');
677
+ citeDiv.classList.add('csl-entry');
678
+ var biblioDiv = window.document.getElementById('ref-' + cite);
679
+ if (biblioDiv) {
680
+ citeDiv.innerHTML = biblioDiv.innerHTML;
681
+ }
682
+ popup.appendChild(citeDiv);
683
+ });
684
+ return popup.innerHTML;
685
+ });
686
+ }
687
+ }
688
+ });
689
+ </script><nav class="page-navigation"><div class="nav-page nav-page-previous">
690
+ <a href="./cw0002multiply.html" class="pagination-link" aria-label="Multiply">
691
+ <i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span></span>
692
+ </a>
693
+ </div>
694
+ <div class="nav-page nav-page-next">
695
+ <a href="./cw0004reducegrow.html" class="pagination-link" aria-label="Beginner - Reduce but Grow!">
696
+ <span class="nav-page-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow!</span></span> <i class="bi bi-arrow-right-short"></i>
697
+ </a>
698
+ </div>
699
+ </nav>
700
+ </div> <!-- /content -->
701
+
702
+
703
+
704
+ </body></html>
cw0004reducegrow.html ADDED
@@ -0,0 +1,699 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
3
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4
+ <meta charset="utf-8">
5
+ <meta name="generator" content="quarto-1.5.53">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
7
+ <title>4&nbsp; Beginner - Reduce but Grow! – Codewars Challenge</title>
8
+ <style>
9
+ code{white-space: pre-wrap;}
10
+ span.smallcaps{font-variant: small-caps;}
11
+ div.columns{display: flex; gap: min(4vw, 1.5em);}
12
+ div.column{flex: auto; overflow-x: auto;}
13
+ div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
14
+ ul.task-list{list-style: none;}
15
+ ul.task-list li input[type="checkbox"] {
16
+ width: 0.8em;
17
+ margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
18
+ vertical-align: middle;
19
+ }
20
+ /* CSS for syntax highlighting */
21
+ pre > code.sourceCode { white-space: pre; position: relative; }
22
+ pre > code.sourceCode > span { line-height: 1.25; }
23
+ pre > code.sourceCode > span:empty { height: 1.2em; }
24
+ .sourceCode { overflow: visible; }
25
+ code.sourceCode > span { color: inherit; text-decoration: inherit; }
26
+ div.sourceCode { margin: 1em 0; }
27
+ pre.sourceCode { margin: 0; }
28
+ @media screen {
29
+ div.sourceCode { overflow: auto; }
30
+ }
31
+ @media print {
32
+ pre > code.sourceCode { white-space: pre-wrap; }
33
+ pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
34
+ }
35
+ pre.numberSource code
36
+ { counter-reset: source-line 0; }
37
+ pre.numberSource code > span
38
+ { position: relative; left: -4em; counter-increment: source-line; }
39
+ pre.numberSource code > span > a:first-child::before
40
+ { content: counter(source-line);
41
+ position: relative; left: -1em; text-align: right; vertical-align: baseline;
42
+ border: none; display: inline-block;
43
+ -webkit-touch-callout: none; -webkit-user-select: none;
44
+ -khtml-user-select: none; -moz-user-select: none;
45
+ -ms-user-select: none; user-select: none;
46
+ padding: 0 4px; width: 4em;
47
+ }
48
+ pre.numberSource { margin-left: 3em; padding-left: 4px; }
49
+ div.sourceCode
50
+ { }
51
+ @media screen {
52
+ pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
53
+ }
54
+ </style>
55
+
56
+ <script src="site_libs/quarto-nav/quarto-nav.js"></script>
57
+ <script src="site_libs/quarto-nav/headroom.min.js"></script>
58
+ <script src="site_libs/clipboard/clipboard.min.js"></script>
59
+ <script src="site_libs/quarto-search/autocomplete.umd.js"></script>
60
+ <script src="site_libs/quarto-search/fuse.min.js"></script>
61
+ <script src="site_libs/quarto-search/quarto-search.js"></script>
62
+ <meta name="quarto:offset" content="./">
63
+ <link href="./cw0005makenegative.html" rel="next">
64
+ <link href="./cw0003countsheep.html" rel="prev">
65
+ <script src="site_libs/quarto-html/quarto.js"></script>
66
+ <script src="site_libs/quarto-html/popper.min.js"></script>
67
+ <script src="site_libs/quarto-html/tippy.umd.min.js"></script>
68
+ <script src="site_libs/quarto-html/anchor.min.js"></script>
69
+ <link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
70
+ <link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
71
+ <script src="site_libs/bootstrap/bootstrap.min.js"></script>
72
+ <link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
73
+ <link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light"><script id="quarto-search-options" type="application/json">{
74
+ "location": "sidebar",
75
+ "copy-button": false,
76
+ "collapse-after": 3,
77
+ "panel-placement": "start",
78
+ "type": "textbox",
79
+ "limit": 50,
80
+ "keyboard-shortcut": [
81
+ "f",
82
+ "/",
83
+ "s"
84
+ ],
85
+ "show-item-context": false,
86
+ "language": {
87
+ "search-no-results-text": "No results",
88
+ "search-matching-documents-text": "matching documents",
89
+ "search-copy-link-title": "Copy link to search",
90
+ "search-hide-matches-text": "Hide additional matches",
91
+ "search-more-match-text": "more match in this document",
92
+ "search-more-matches-text": "more matches in this document",
93
+ "search-clear-button-title": "Clear",
94
+ "search-text-placeholder": "",
95
+ "search-detached-cancel-button-title": "Cancel",
96
+ "search-submit-button-title": "Submit",
97
+ "search-label": "Search"
98
+ }
99
+ }</script><link rel="stylesheet" href="style.css">
100
+ <meta name="twitter:title" content="4&nbsp; Beginner - Reduce but Grow! – Codewars Challenge">
101
+ <meta name="twitter:description" content="">
102
+ <meta name="twitter:card" content="summary">
103
+ </head>
104
+ <body class="nav-sidebar floating">
105
+
106
+ <div id="quarto-search-results"></div>
107
+ <header id="quarto-header" class="headroom fixed-top"><nav class="quarto-secondary-nav"><div class="container-fluid d-flex">
108
+ <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" role="button" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
109
+ <i class="bi bi-layout-text-sidebar-reverse"></i>
110
+ </button>
111
+ <nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./cw0001evenodd.html">2025</a></li><li class="breadcrumb-item"><a href="./cw0004reducegrow.html"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow!</span></a></li></ol></nav>
112
+ <a class="flex-grow-1" role="navigation" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
113
+ </a>
114
+ <button type="button" class="btn quarto-search-button" aria-label="Search" onclick="window.quartoOpenSearch();">
115
+ <i class="bi bi-search"></i>
116
+ </button>
117
+ </div>
118
+ </nav></header><!-- content --><div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
119
+ <!-- sidebar -->
120
+ <nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal quarto-sidebar-collapse-item sidebar-navigation floating overflow-auto"><div class="pt-lg-2 mt-2 text-left sidebar-header">
121
+ <div class="sidebar-title mb-0 py-0">
122
+ <a href="./">Codewars Challenge</a>
123
+ <div class="sidebar-tools-main">
124
+ <a href="https://huggingface.co/spaces/aephidayatuloh/codewarschallenge/tree/main" title="Source Code" class="quarto-navigation-tool px-1" aria-label="Source Code"><i class="bi bi-git"></i></a>
125
+ </div>
126
+ </div>
127
+ </div>
128
+ <div class="mt-2 flex-shrink-0 align-items-center">
129
+ <div class="sidebar-search">
130
+ <div id="quarto-search" class="" title="Search"></div>
131
+ </div>
132
+ </div>
133
+ <div class="sidebar-menu-container">
134
+ <ul class="list-unstyled mt-1">
135
+ <li class="sidebar-item">
136
+ <div class="sidebar-item-container">
137
+ <a href="./index.html" class="sidebar-item-text sidebar-link">
138
+ <span class="menu-text">Pengantar</span></a>
139
+ </div>
140
+ </li>
141
+ <li class="sidebar-item sidebar-item-section">
142
+ <div class="sidebar-item-container">
143
+ <a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true">
144
+ <span class="menu-text">2025</span></a>
145
+ <a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true" aria-label="Toggle section">
146
+ <i class="bi bi-chevron-right ms-2"></i>
147
+ </a>
148
+ </div>
149
+ <ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
150
+ <li class="sidebar-item">
151
+ <div class="sidebar-item-container">
152
+ <a href="./cw0001evenodd.html" class="sidebar-item-text sidebar-link">
153
+ <span class="menu-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span></span></a>
154
+ </div>
155
+ </li>
156
+ <li class="sidebar-item">
157
+ <div class="sidebar-item-container">
158
+ <a href="./cw0002multiply.html" class="sidebar-item-text sidebar-link">
159
+ <span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span></span></a>
160
+ </div>
161
+ </li>
162
+ <li class="sidebar-item">
163
+ <div class="sidebar-item-container">
164
+ <a href="./cw0003countsheep.html" class="sidebar-item-text sidebar-link">
165
+ <span class="menu-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Count Sheep</span></span></a>
166
+ </div>
167
+ </li>
168
+ <li class="sidebar-item">
169
+ <div class="sidebar-item-container">
170
+ <a href="./cw0004reducegrow.html" class="sidebar-item-text sidebar-link active">
171
+ <span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow!</span></span></a>
172
+ </div>
173
+ </li>
174
+ <li class="sidebar-item">
175
+ <div class="sidebar-item-container">
176
+ <a href="./cw0005makenegative.html" class="sidebar-item-text sidebar-link">
177
+ <span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Return Negative</span></span></a>
178
+ </div>
179
+ </li>
180
+ </ul>
181
+ </li>
182
+ </ul>
183
+ </div>
184
+ </nav><div id="quarto-sidebar-glass" class="quarto-sidebar-collapse-item" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item"></div>
185
+ <!-- margin-sidebar -->
186
+ <div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
187
+ <nav id="TOC" role="doc-toc" class="toc-active" data-toc-expanded="99"><h2 id="toc-title">Table of contents</h2>
188
+
189
+ <ul>
190
+ <li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">4.1</span> Instruction</a></li>
191
+ <li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">4.2</span> YouTube Video</a></li>
192
+ <li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">4.3</span> Solution Code</a></li>
193
+ <li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">4.4</span> Test</a></li>
194
+ </ul></nav>
195
+ </div>
196
+ <!-- main -->
197
+ <main class="content" id="quarto-document-content"><header id="title-block-header" class="quarto-title-block default"><nav class="quarto-page-breadcrumbs quarto-title-breadcrumbs d-none d-lg-block" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./cw0001evenodd.html">2025</a></li><li class="breadcrumb-item"><a href="./cw0004reducegrow.html"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow!</span></a></li></ol></nav><div class="quarto-title">
198
+ <h1 class="title">
199
+ <span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow!</span>
200
+ </h1>
201
+ </div>
202
+
203
+
204
+
205
+ <div class="quarto-title-meta">
206
+
207
+
208
+
209
+
210
+ </div>
211
+
212
+
213
+
214
+ </header><p><span class="badge rounded-pill quarto-badge">8Kyu</span> Tantangan #4/366 - 04 Feb 2025</p>
215
+ <p><a href="https://www.codewars.com/kata/57f780909f7e8e3183000078" class="uri">https://www.codewars.com/kata/57f780909f7e8e3183000078</a></p>
216
+ <h2 data-number="4.1" id="instruction" class="anchored">
217
+ <span class="header-section-number">4.1</span> Instruction</h2>
218
+ <blockquote class="blockquote">
219
+ <p>Given a non-empty array of integers, return the result of multiplying the values together in order.</p>
220
+ </blockquote>
221
+ <p>Example:<br><code>[1, 2, 3, 4] =&gt; 1 * 2 * 3 * 4 = 24</code></p>
222
+ <h2 data-number="4.2" id="youtube-video" class="anchored">
223
+ <span class="header-section-number">4.2</span> YouTube Video</h2>
224
+ <div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/L8aczEhqymk" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
225
+ <h2 data-number="4.3" id="solution-code" class="anchored">
226
+ <span class="header-section-number">4.3</span> Solution Code</h2>
227
+ <p>Solusi bar-bar</p>
228
+ <div class="cell">
229
+ <div class="sourceCode" id="cb1"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">grow</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">arr</span><span class="op">)</span> <span class="op">{</span></span>
230
+ <span> <span class="va">result</span> <span class="op">&lt;-</span> <span class="fl">1</span></span>
231
+ <span> <span class="kw">for</span><span class="op">(</span><span class="va">i</span> <span class="kw">in</span> <span class="va">arr</span><span class="op">)</span><span class="op">{</span></span>
232
+ <span> <span class="va">result</span> <span class="op">&lt;-</span> <span class="va">result</span> <span class="op">*</span> <span class="va">i</span></span>
233
+ <span> <span class="op">}</span></span>
234
+ <span> <span class="kw"><a href="https://rdrr.io/r/base/function.html">return</a></span><span class="op">(</span><span class="va">result</span><span class="op">)</span></span>
235
+ <span><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
236
+ </div>
237
+ <p>Solusi simple</p>
238
+ <div class="cell">
239
+ <div class="sourceCode" id="cb2"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co"># grow &lt;- function(arr) prod(arr)</span></span>
240
+ <span><span class="va">grow</span> <span class="op">&lt;-</span> <span class="va">prod</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
241
+ </div>
242
+ <p>Function <code><a href="https://rdrr.io/r/base/prod.html">prod()</a></code> adalah function untuk mengalikan nilai dari satu vector numeric, cara kerjanya sama persis dengan yang diinginkan. Oleh karena itu cukup meng-copy function <code><a href="https://rdrr.io/r/base/prod.html">prod()</a></code> sebagai <code>grow()</code>.</p>
243
+ <h2 data-number="4.4" id="test" class="anchored">
244
+ <span class="header-section-number">4.4</span> Test</h2>
245
+ <div class="cell">
246
+ <div class="sourceCode" id="cb3"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://testthat.r-lib.org">testthat</a></span><span class="op">)</span></span>
247
+ <span><span class="fu"><a href="https://testthat.r-lib.org/reference/test_that.html">test_that</a></span><span class="op">(</span><span class="st">"basic tests"</span>, <span class="op">{</span></span>
248
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">grow</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">1</span>, <span class="fl">2</span>, <span class="fl">3</span><span class="op">)</span><span class="op">)</span>, <span class="fl">6</span><span class="op">)</span></span>
249
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">grow</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">4</span>, <span class="fl">1</span>, <span class="fl">1</span>, <span class="fl">1</span>, <span class="fl">4</span><span class="op">)</span><span class="op">)</span>, <span class="fl">16</span><span class="op">)</span></span>
250
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">grow</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="fl">2</span>, <span class="fl">2</span>, <span class="fl">2</span>, <span class="fl">2</span>, <span class="fl">2</span>, <span class="fl">2</span><span class="op">)</span><span class="op">)</span>, <span class="fl">64</span><span class="op">)</span></span>
251
+ <span><span class="op">}</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
252
+ <div class="cell-output cell-output-stdout">
253
+ <pre><code>## Test passed 🎉</code></pre>
254
+ </div>
255
+ </div>
256
+ <hr>
257
+ <p><strong>Supported by</strong></p>
258
+ <div class="quarto-figure quarto-figure-center">
259
+ <figure class="figure"><p><img src="new_starcore_logo.png" class="img-fluid figure-img"></p>
260
+ <figcaption>StarCore Analytics</figcaption></figure>
261
+ </div>
262
+
263
+
264
+
265
+ </main><!-- /main --><script id="quarto-html-after-body" type="application/javascript">
266
+ window.document.addEventListener("DOMContentLoaded", function (event) {
267
+ const toggleBodyColorMode = (bsSheetEl) => {
268
+ const mode = bsSheetEl.getAttribute("data-mode");
269
+ const bodyEl = window.document.querySelector("body");
270
+ if (mode === "dark") {
271
+ bodyEl.classList.add("quarto-dark");
272
+ bodyEl.classList.remove("quarto-light");
273
+ } else {
274
+ bodyEl.classList.add("quarto-light");
275
+ bodyEl.classList.remove("quarto-dark");
276
+ }
277
+ }
278
+ const toggleBodyColorPrimary = () => {
279
+ const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
280
+ if (bsSheetEl) {
281
+ toggleBodyColorMode(bsSheetEl);
282
+ }
283
+ }
284
+ toggleBodyColorPrimary();
285
+ const icon = "";
286
+ const anchorJS = new window.AnchorJS();
287
+ anchorJS.options = {
288
+ placement: 'right',
289
+ icon: icon
290
+ };
291
+ anchorJS.add('.anchored');
292
+ const isCodeAnnotation = (el) => {
293
+ for (const clz of el.classList) {
294
+ if (clz.startsWith('code-annotation-')) {
295
+ return true;
296
+ }
297
+ }
298
+ return false;
299
+ }
300
+ const onCopySuccess = function(e) {
301
+ // button target
302
+ const button = e.trigger;
303
+ // don't keep focus
304
+ button.blur();
305
+ // flash "checked"
306
+ button.classList.add('code-copy-button-checked');
307
+ var currentTitle = button.getAttribute("title");
308
+ button.setAttribute("title", "Copied!");
309
+ let tooltip;
310
+ if (window.bootstrap) {
311
+ button.setAttribute("data-bs-toggle", "tooltip");
312
+ button.setAttribute("data-bs-placement", "left");
313
+ button.setAttribute("data-bs-title", "Copied!");
314
+ tooltip = new bootstrap.Tooltip(button,
315
+ { trigger: "manual",
316
+ customClass: "code-copy-button-tooltip",
317
+ offset: [0, -8]});
318
+ tooltip.show();
319
+ }
320
+ setTimeout(function() {
321
+ if (tooltip) {
322
+ tooltip.hide();
323
+ button.removeAttribute("data-bs-title");
324
+ button.removeAttribute("data-bs-toggle");
325
+ button.removeAttribute("data-bs-placement");
326
+ }
327
+ button.setAttribute("title", currentTitle);
328
+ button.classList.remove('code-copy-button-checked');
329
+ }, 1000);
330
+ // clear code selection
331
+ e.clearSelection();
332
+ }
333
+ const getTextToCopy = function(trigger) {
334
+ const codeEl = trigger.previousElementSibling.cloneNode(true);
335
+ for (const childEl of codeEl.children) {
336
+ if (isCodeAnnotation(childEl)) {
337
+ childEl.remove();
338
+ }
339
+ }
340
+ return codeEl.innerText;
341
+ }
342
+ const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
343
+ text: getTextToCopy
344
+ });
345
+ clipboard.on('success', onCopySuccess);
346
+ if (window.document.getElementById('quarto-embedded-source-code-modal')) {
347
+ // For code content inside modals, clipBoardJS needs to be initialized with a container option
348
+ // TODO: Check when it could be a function (https://github.com/zenorocha/clipboard.js/issues/860)
349
+ const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
350
+ text: getTextToCopy,
351
+ container: window.document.getElementById('quarto-embedded-source-code-modal')
352
+ });
353
+ clipboardModal.on('success', onCopySuccess);
354
+ }
355
+ var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
356
+ var mailtoRegex = new RegExp(/^mailto:/);
357
+ var filterRegex = new RegExp("https:\/\/huggingface\.co\/spaces\/aephidayatuloh\/codewarschallenge\/");
358
+ var isInternal = (href) => {
359
+ return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
360
+ }
361
+ // Inspect non-navigation links and adorn them if external
362
+ var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
363
+ for (var i=0; i<links.length; i++) {
364
+ const link = links[i];
365
+ if (!isInternal(link.href)) {
366
+ // undo the damage that might have been done by quarto-nav.js in the case of
367
+ // links that we want to consider external
368
+ if (link.dataset.originalHref !== undefined) {
369
+ link.href = link.dataset.originalHref;
370
+ }
371
+ }
372
+ }
373
+ function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
374
+ const config = {
375
+ allowHTML: true,
376
+ maxWidth: 500,
377
+ delay: 100,
378
+ arrow: false,
379
+ appendTo: function(el) {
380
+ return el.parentElement;
381
+ },
382
+ interactive: true,
383
+ interactiveBorder: 10,
384
+ theme: 'quarto',
385
+ placement: 'bottom-start',
386
+ };
387
+ if (contentFn) {
388
+ config.content = contentFn;
389
+ }
390
+ if (onTriggerFn) {
391
+ config.onTrigger = onTriggerFn;
392
+ }
393
+ if (onUntriggerFn) {
394
+ config.onUntrigger = onUntriggerFn;
395
+ }
396
+ window.tippy(el, config);
397
+ }
398
+ const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
399
+ for (var i=0; i<noterefs.length; i++) {
400
+ const ref = noterefs[i];
401
+ tippyHover(ref, function() {
402
+ // use id or data attribute instead here
403
+ let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
404
+ try { href = new URL(href).hash; } catch {}
405
+ const id = href.replace(/^#\/?/, "");
406
+ const note = window.document.getElementById(id);
407
+ if (note) {
408
+ return note.innerHTML;
409
+ } else {
410
+ return "";
411
+ }
412
+ });
413
+ }
414
+ const xrefs = window.document.querySelectorAll('a.quarto-xref');
415
+ const processXRef = (id, note) => {
416
+ // Strip column container classes
417
+ const stripColumnClz = (el) => {
418
+ el.classList.remove("page-full", "page-columns");
419
+ if (el.children) {
420
+ for (const child of el.children) {
421
+ stripColumnClz(child);
422
+ }
423
+ }
424
+ }
425
+ stripColumnClz(note)
426
+ if (id === null || id.startsWith('sec-')) {
427
+ // Special case sections, only their first couple elements
428
+ const container = document.createElement("div");
429
+ if (note.children && note.children.length > 2) {
430
+ container.appendChild(note.children[0].cloneNode(true));
431
+ for (let i = 1; i < note.children.length; i++) {
432
+ const child = note.children[i];
433
+ if (child.tagName === "P" && child.innerText === "") {
434
+ continue;
435
+ } else {
436
+ container.appendChild(child.cloneNode(true));
437
+ break;
438
+ }
439
+ }
440
+ if (window.Quarto?.typesetMath) {
441
+ window.Quarto.typesetMath(container);
442
+ }
443
+ return container.innerHTML
444
+ } else {
445
+ if (window.Quarto?.typesetMath) {
446
+ window.Quarto.typesetMath(note);
447
+ }
448
+ return note.innerHTML;
449
+ }
450
+ } else {
451
+ // Remove any anchor links if they are present
452
+ const anchorLink = note.querySelector('a.anchorjs-link');
453
+ if (anchorLink) {
454
+ anchorLink.remove();
455
+ }
456
+ if (window.Quarto?.typesetMath) {
457
+ window.Quarto.typesetMath(note);
458
+ }
459
+ // TODO in 1.5, we should make sure this works without a callout special case
460
+ if (note.classList.contains("callout")) {
461
+ return note.outerHTML;
462
+ } else {
463
+ return note.innerHTML;
464
+ }
465
+ }
466
+ }
467
+ for (var i=0; i<xrefs.length; i++) {
468
+ const xref = xrefs[i];
469
+ tippyHover(xref, undefined, function(instance) {
470
+ instance.disable();
471
+ let url = xref.getAttribute('href');
472
+ let hash = undefined;
473
+ if (url.startsWith('#')) {
474
+ hash = url;
475
+ } else {
476
+ try { hash = new URL(url).hash; } catch {}
477
+ }
478
+ if (hash) {
479
+ const id = hash.replace(/^#\/?/, "");
480
+ const note = window.document.getElementById(id);
481
+ if (note !== null) {
482
+ try {
483
+ const html = processXRef(id, note.cloneNode(true));
484
+ instance.setContent(html);
485
+ } finally {
486
+ instance.enable();
487
+ instance.show();
488
+ }
489
+ } else {
490
+ // See if we can fetch this
491
+ fetch(url.split('#')[0])
492
+ .then(res => res.text())
493
+ .then(html => {
494
+ const parser = new DOMParser();
495
+ const htmlDoc = parser.parseFromString(html, "text/html");
496
+ const note = htmlDoc.getElementById(id);
497
+ if (note !== null) {
498
+ const html = processXRef(id, note);
499
+ instance.setContent(html);
500
+ }
501
+ }).finally(() => {
502
+ instance.enable();
503
+ instance.show();
504
+ });
505
+ }
506
+ } else {
507
+ // See if we can fetch a full url (with no hash to target)
508
+ // This is a special case and we should probably do some content thinning / targeting
509
+ fetch(url)
510
+ .then(res => res.text())
511
+ .then(html => {
512
+ const parser = new DOMParser();
513
+ const htmlDoc = parser.parseFromString(html, "text/html");
514
+ const note = htmlDoc.querySelector('main.content');
515
+ if (note !== null) {
516
+ // This should only happen for chapter cross references
517
+ // (since there is no id in the URL)
518
+ // remove the first header
519
+ if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
520
+ note.children[0].remove();
521
+ }
522
+ const html = processXRef(null, note);
523
+ instance.setContent(html);
524
+ }
525
+ }).finally(() => {
526
+ instance.enable();
527
+ instance.show();
528
+ });
529
+ }
530
+ }, function(instance) {
531
+ });
532
+ }
533
+ let selectedAnnoteEl;
534
+ const selectorForAnnotation = ( cell, annotation) => {
535
+ let cellAttr = 'data-code-cell="' + cell + '"';
536
+ let lineAttr = 'data-code-annotation="' + annotation + '"';
537
+ const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
538
+ return selector;
539
+ }
540
+ const selectCodeLines = (annoteEl) => {
541
+ const doc = window.document;
542
+ const targetCell = annoteEl.getAttribute("data-target-cell");
543
+ const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
544
+ const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
545
+ const lines = annoteSpan.getAttribute("data-code-lines").split(",");
546
+ const lineIds = lines.map((line) => {
547
+ return targetCell + "-" + line;
548
+ })
549
+ let top = null;
550
+ let height = null;
551
+ let parent = null;
552
+ if (lineIds.length > 0) {
553
+ //compute the position of the single el (top and bottom and make a div)
554
+ const el = window.document.getElementById(lineIds[0]);
555
+ top = el.offsetTop;
556
+ height = el.offsetHeight;
557
+ parent = el.parentElement.parentElement;
558
+ if (lineIds.length > 1) {
559
+ const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
560
+ const bottom = lastEl.offsetTop + lastEl.offsetHeight;
561
+ height = bottom - top;
562
+ }
563
+ if (top !== null && height !== null && parent !== null) {
564
+ // cook up a div (if necessary) and position it
565
+ let div = window.document.getElementById("code-annotation-line-highlight");
566
+ if (div === null) {
567
+ div = window.document.createElement("div");
568
+ div.setAttribute("id", "code-annotation-line-highlight");
569
+ div.style.position = 'absolute';
570
+ parent.appendChild(div);
571
+ }
572
+ div.style.top = top - 2 + "px";
573
+ div.style.height = height + 4 + "px";
574
+ div.style.left = 0;
575
+ let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
576
+ if (gutterDiv === null) {
577
+ gutterDiv = window.document.createElement("div");
578
+ gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
579
+ gutterDiv.style.position = 'absolute';
580
+ const codeCell = window.document.getElementById(targetCell);
581
+ const gutter = codeCell.querySelector('.code-annotation-gutter');
582
+ gutter.appendChild(gutterDiv);
583
+ }
584
+ gutterDiv.style.top = top - 2 + "px";
585
+ gutterDiv.style.height = height + 4 + "px";
586
+ }
587
+ selectedAnnoteEl = annoteEl;
588
+ }
589
+ };
590
+ const unselectCodeLines = () => {
591
+ const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
592
+ elementsIds.forEach((elId) => {
593
+ const div = window.document.getElementById(elId);
594
+ if (div) {
595
+ div.remove();
596
+ }
597
+ });
598
+ selectedAnnoteEl = undefined;
599
+ };
600
+ // Handle positioning of the toggle
601
+ window.addEventListener(
602
+ "resize",
603
+ throttle(() => {
604
+ elRect = undefined;
605
+ if (selectedAnnoteEl) {
606
+ selectCodeLines(selectedAnnoteEl);
607
+ }
608
+ }, 10)
609
+ );
610
+ function throttle(fn, ms) {
611
+ let throttle = false;
612
+ let timer;
613
+ return (...args) => {
614
+ if(!throttle) { // first call gets through
615
+ fn.apply(this, args);
616
+ throttle = true;
617
+ } else { // all the others get throttled
618
+ if(timer) clearTimeout(timer); // cancel #2
619
+ timer = setTimeout(() => {
620
+ fn.apply(this, args);
621
+ timer = throttle = false;
622
+ }, ms);
623
+ }
624
+ };
625
+ }
626
+ // Attach click handler to the DT
627
+ const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
628
+ for (const annoteDlNode of annoteDls) {
629
+ annoteDlNode.addEventListener('click', (event) => {
630
+ const clickedEl = event.target;
631
+ if (clickedEl !== selectedAnnoteEl) {
632
+ unselectCodeLines();
633
+ const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
634
+ if (activeEl) {
635
+ activeEl.classList.remove('code-annotation-active');
636
+ }
637
+ selectCodeLines(clickedEl);
638
+ clickedEl.classList.add('code-annotation-active');
639
+ } else {
640
+ // Unselect the line
641
+ unselectCodeLines();
642
+ clickedEl.classList.remove('code-annotation-active');
643
+ }
644
+ });
645
+ }
646
+ const findCites = (el) => {
647
+ const parentEl = el.parentElement;
648
+ if (parentEl) {
649
+ const cites = parentEl.dataset.cites;
650
+ if (cites) {
651
+ return {
652
+ el,
653
+ cites: cites.split(' ')
654
+ };
655
+ } else {
656
+ return findCites(el.parentElement)
657
+ }
658
+ } else {
659
+ return undefined;
660
+ }
661
+ };
662
+ var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
663
+ for (var i=0; i<bibliorefs.length; i++) {
664
+ const ref = bibliorefs[i];
665
+ const citeInfo = findCites(ref);
666
+ if (citeInfo) {
667
+ tippyHover(citeInfo.el, function() {
668
+ var popup = window.document.createElement('div');
669
+ citeInfo.cites.forEach(function(cite) {
670
+ var citeDiv = window.document.createElement('div');
671
+ citeDiv.classList.add('hanging-indent');
672
+ citeDiv.classList.add('csl-entry');
673
+ var biblioDiv = window.document.getElementById('ref-' + cite);
674
+ if (biblioDiv) {
675
+ citeDiv.innerHTML = biblioDiv.innerHTML;
676
+ }
677
+ popup.appendChild(citeDiv);
678
+ });
679
+ return popup.innerHTML;
680
+ });
681
+ }
682
+ }
683
+ });
684
+ </script><nav class="page-navigation"><div class="nav-page nav-page-previous">
685
+ <a href="./cw0003countsheep.html" class="pagination-link" aria-label="Count Sheep">
686
+ <i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Count Sheep</span></span>
687
+ </a>
688
+ </div>
689
+ <div class="nav-page nav-page-next">
690
+ <a href="./cw0005makenegative.html" class="pagination-link" aria-label="Return Negative">
691
+ <span class="nav-page-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Return Negative</span></span> <i class="bi bi-arrow-right-short"></i>
692
+ </a>
693
+ </div>
694
+ </nav>
695
+ </div> <!-- /content -->
696
+
697
+
698
+
699
+ </body></html>
cw0005makenegative.html ADDED
@@ -0,0 +1,703 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
3
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4
+ <meta charset="utf-8">
5
+ <meta name="generator" content="quarto-1.5.53">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
7
+ <title>5&nbsp; Return Negative – Codewars Challenge</title>
8
+ <style>
9
+ code{white-space: pre-wrap;}
10
+ span.smallcaps{font-variant: small-caps;}
11
+ div.columns{display: flex; gap: min(4vw, 1.5em);}
12
+ div.column{flex: auto; overflow-x: auto;}
13
+ div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
14
+ ul.task-list{list-style: none;}
15
+ ul.task-list li input[type="checkbox"] {
16
+ width: 0.8em;
17
+ margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
18
+ vertical-align: middle;
19
+ }
20
+ /* CSS for syntax highlighting */
21
+ pre > code.sourceCode { white-space: pre; position: relative; }
22
+ pre > code.sourceCode > span { line-height: 1.25; }
23
+ pre > code.sourceCode > span:empty { height: 1.2em; }
24
+ .sourceCode { overflow: visible; }
25
+ code.sourceCode > span { color: inherit; text-decoration: inherit; }
26
+ div.sourceCode { margin: 1em 0; }
27
+ pre.sourceCode { margin: 0; }
28
+ @media screen {
29
+ div.sourceCode { overflow: auto; }
30
+ }
31
+ @media print {
32
+ pre > code.sourceCode { white-space: pre-wrap; }
33
+ pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
34
+ }
35
+ pre.numberSource code
36
+ { counter-reset: source-line 0; }
37
+ pre.numberSource code > span
38
+ { position: relative; left: -4em; counter-increment: source-line; }
39
+ pre.numberSource code > span > a:first-child::before
40
+ { content: counter(source-line);
41
+ position: relative; left: -1em; text-align: right; vertical-align: baseline;
42
+ border: none; display: inline-block;
43
+ -webkit-touch-callout: none; -webkit-user-select: none;
44
+ -khtml-user-select: none; -moz-user-select: none;
45
+ -ms-user-select: none; user-select: none;
46
+ padding: 0 4px; width: 4em;
47
+ }
48
+ pre.numberSource { margin-left: 3em; padding-left: 4px; }
49
+ div.sourceCode
50
+ { }
51
+ @media screen {
52
+ pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
53
+ }
54
+ </style>
55
+
56
+ <script src="site_libs/quarto-nav/quarto-nav.js"></script>
57
+ <script src="site_libs/quarto-nav/headroom.min.js"></script>
58
+ <script src="site_libs/clipboard/clipboard.min.js"></script>
59
+ <script src="site_libs/quarto-search/autocomplete.umd.js"></script>
60
+ <script src="site_libs/quarto-search/fuse.min.js"></script>
61
+ <script src="site_libs/quarto-search/quarto-search.js"></script>
62
+ <meta name="quarto:offset" content="./">
63
+ <link href="./cw0004reducegrow.html" rel="prev">
64
+ <script src="site_libs/quarto-html/quarto.js"></script>
65
+ <script src="site_libs/quarto-html/popper.min.js"></script>
66
+ <script src="site_libs/quarto-html/tippy.umd.min.js"></script>
67
+ <script src="site_libs/quarto-html/anchor.min.js"></script>
68
+ <link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
69
+ <link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
70
+ <script src="site_libs/bootstrap/bootstrap.min.js"></script>
71
+ <link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
72
+ <link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light"><script id="quarto-search-options" type="application/json">{
73
+ "location": "sidebar",
74
+ "copy-button": false,
75
+ "collapse-after": 3,
76
+ "panel-placement": "start",
77
+ "type": "textbox",
78
+ "limit": 50,
79
+ "keyboard-shortcut": [
80
+ "f",
81
+ "/",
82
+ "s"
83
+ ],
84
+ "show-item-context": false,
85
+ "language": {
86
+ "search-no-results-text": "No results",
87
+ "search-matching-documents-text": "matching documents",
88
+ "search-copy-link-title": "Copy link to search",
89
+ "search-hide-matches-text": "Hide additional matches",
90
+ "search-more-match-text": "more match in this document",
91
+ "search-more-matches-text": "more matches in this document",
92
+ "search-clear-button-title": "Clear",
93
+ "search-text-placeholder": "",
94
+ "search-detached-cancel-button-title": "Cancel",
95
+ "search-submit-button-title": "Submit",
96
+ "search-label": "Search"
97
+ }
98
+ }</script><link rel="stylesheet" href="style.css">
99
+ <meta name="twitter:title" content="5&nbsp; Return Negative – Codewars Challenge">
100
+ <meta name="twitter:description" content="">
101
+ <meta name="twitter:card" content="summary">
102
+ </head>
103
+ <body class="nav-sidebar floating">
104
+
105
+ <div id="quarto-search-results"></div>
106
+ <header id="quarto-header" class="headroom fixed-top"><nav class="quarto-secondary-nav"><div class="container-fluid d-flex">
107
+ <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" role="button" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
108
+ <i class="bi bi-layout-text-sidebar-reverse"></i>
109
+ </button>
110
+ <nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./cw0001evenodd.html">2025</a></li><li class="breadcrumb-item"><a href="./cw0005makenegative.html"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Return Negative</span></a></li></ol></nav>
111
+ <a class="flex-grow-1" role="navigation" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
112
+ </a>
113
+ <button type="button" class="btn quarto-search-button" aria-label="Search" onclick="window.quartoOpenSearch();">
114
+ <i class="bi bi-search"></i>
115
+ </button>
116
+ </div>
117
+ </nav></header><!-- content --><div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
118
+ <!-- sidebar -->
119
+ <nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal quarto-sidebar-collapse-item sidebar-navigation floating overflow-auto"><div class="pt-lg-2 mt-2 text-left sidebar-header">
120
+ <div class="sidebar-title mb-0 py-0">
121
+ <a href="./">Codewars Challenge</a>
122
+ <div class="sidebar-tools-main">
123
+ <a href="https://huggingface.co/spaces/aephidayatuloh/codewarschallenge/tree/main" title="Source Code" class="quarto-navigation-tool px-1" aria-label="Source Code"><i class="bi bi-git"></i></a>
124
+ </div>
125
+ </div>
126
+ </div>
127
+ <div class="mt-2 flex-shrink-0 align-items-center">
128
+ <div class="sidebar-search">
129
+ <div id="quarto-search" class="" title="Search"></div>
130
+ </div>
131
+ </div>
132
+ <div class="sidebar-menu-container">
133
+ <ul class="list-unstyled mt-1">
134
+ <li class="sidebar-item">
135
+ <div class="sidebar-item-container">
136
+ <a href="./index.html" class="sidebar-item-text sidebar-link">
137
+ <span class="menu-text">Pengantar</span></a>
138
+ </div>
139
+ </li>
140
+ <li class="sidebar-item sidebar-item-section">
141
+ <div class="sidebar-item-container">
142
+ <a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true">
143
+ <span class="menu-text">2025</span></a>
144
+ <a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="true" aria-label="Toggle section">
145
+ <i class="bi bi-chevron-right ms-2"></i>
146
+ </a>
147
+ </div>
148
+ <ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 show">
149
+ <li class="sidebar-item">
150
+ <div class="sidebar-item-container">
151
+ <a href="./cw0001evenodd.html" class="sidebar-item-text sidebar-link">
152
+ <span class="menu-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span></span></a>
153
+ </div>
154
+ </li>
155
+ <li class="sidebar-item">
156
+ <div class="sidebar-item-container">
157
+ <a href="./cw0002multiply.html" class="sidebar-item-text sidebar-link">
158
+ <span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span></span></a>
159
+ </div>
160
+ </li>
161
+ <li class="sidebar-item">
162
+ <div class="sidebar-item-container">
163
+ <a href="./cw0003countsheep.html" class="sidebar-item-text sidebar-link">
164
+ <span class="menu-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Count Sheep</span></span></a>
165
+ </div>
166
+ </li>
167
+ <li class="sidebar-item">
168
+ <div class="sidebar-item-container">
169
+ <a href="./cw0004reducegrow.html" class="sidebar-item-text sidebar-link">
170
+ <span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow!</span></span></a>
171
+ </div>
172
+ </li>
173
+ <li class="sidebar-item">
174
+ <div class="sidebar-item-container">
175
+ <a href="./cw0005makenegative.html" class="sidebar-item-text sidebar-link active">
176
+ <span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Return Negative</span></span></a>
177
+ </div>
178
+ </li>
179
+ </ul>
180
+ </li>
181
+ </ul>
182
+ </div>
183
+ </nav><div id="quarto-sidebar-glass" class="quarto-sidebar-collapse-item" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item"></div>
184
+ <!-- margin-sidebar -->
185
+ <div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
186
+ <nav id="TOC" role="doc-toc" class="toc-active" data-toc-expanded="99"><h2 id="toc-title">Table of contents</h2>
187
+
188
+ <ul>
189
+ <li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">5.1</span> Instruction</a></li>
190
+ <li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">5.2</span> YouTube Video</a></li>
191
+ <li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">5.3</span> Solution Code</a></li>
192
+ <li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">5.4</span> Test</a></li>
193
+ </ul></nav>
194
+ </div>
195
+ <!-- main -->
196
+ <main class="content" id="quarto-document-content"><header id="title-block-header" class="quarto-title-block default"><nav class="quarto-page-breadcrumbs quarto-title-breadcrumbs d-none d-lg-block" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./cw0001evenodd.html">2025</a></li><li class="breadcrumb-item"><a href="./cw0005makenegative.html"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Return Negative</span></a></li></ol></nav><div class="quarto-title">
197
+ <h1 class="title">
198
+ <span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Return Negative</span>
199
+ </h1>
200
+ </div>
201
+
202
+
203
+
204
+ <div class="quarto-title-meta">
205
+
206
+
207
+
208
+
209
+ </div>
210
+
211
+
212
+
213
+ </header><p><span class="badge rounded-pill quarto-badge">8Kyu</span> Tantangan #5/366 - 05 Feb 2025</p>
214
+ <p><a href="https://www.codewars.com/kata/55685cd7ad70877c23000102" class="uri">https://www.codewars.com/kata/55685cd7ad70877c23000102</a></p>
215
+ <h2 data-number="5.1" id="instruction" class="anchored">
216
+ <span class="header-section-number">5.1</span> Instruction</h2>
217
+ <blockquote class="blockquote">
218
+ <p>In this simple assignment you are given a number and have to make it negative. But maybe the number is already negative?</p>
219
+ </blockquote>
220
+ <p>Examples</p>
221
+ <div class="cell">
222
+ <div class="sourceCode" id="cb1"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu">make_negative</span><span class="op">(</span><span class="fl">1</span><span class="op">)</span>; <span class="co"># return -1 </span></span>
223
+ <span><span class="fu">make_negative</span><span class="op">(</span><span class="op">-</span><span class="fl">5</span><span class="op">)</span>; <span class="co"># return -5</span></span>
224
+ <span><span class="fu">make_negative</span><span class="op">(</span><span class="fl">0</span><span class="op">)</span>; <span class="co"># return 0</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
225
+ </div>
226
+ <p>Notes</p>
227
+ <ul>
228
+ <li>The number can be negative already, in which case no change is required.<br>
229
+ </li>
230
+ <li>Zero (0) is not checked for any specific sign. Negative zeros make no mathematical sense.</li>
231
+ </ul>
232
+ <h2 data-number="5.2" id="youtube-video" class="anchored">
233
+ <span class="header-section-number">5.2</span> YouTube Video</h2>
234
+ <div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/L8aczEhqymk" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
235
+ <h2 data-number="5.3" id="solution-code" class="anchored">
236
+ <span class="header-section-number">5.3</span> Solution Code</h2>
237
+ <p>Solusi bar-bar</p>
238
+ <div class="cell">
239
+ <div class="sourceCode" id="cb2"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">make_negative</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">num</span><span class="op">)</span><span class="op">{</span></span>
240
+ <span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op">(</span><span class="va">num</span> <span class="op">&lt;=</span> <span class="fl">0</span>, <span class="va">num</span>, <span class="op">-</span><span class="fl">1</span><span class="op">*</span><span class="va">num</span><span class="op">)</span></span>
241
+ <span><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
242
+ </div>
243
+ <p>Solusi simple</p>
244
+ <div class="cell">
245
+ <div class="sourceCode" id="cb3"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="va">make_negative</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">num</span><span class="op">)</span><span class="op">-</span><span class="fu"><a href="https://rdrr.io/r/base/MathFun.html">abs</a></span><span class="op">(</span><span class="va">num</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
246
+ </div>
247
+ <h2 data-number="5.4" id="test" class="anchored">
248
+ <span class="header-section-number">5.4</span> Test</h2>
249
+ <div class="cell">
250
+ <div class="sourceCode" id="cb4"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://testthat.r-lib.org">testthat</a></span><span class="op">)</span></span>
251
+ <span></span>
252
+ <span><span class="fu"><a href="https://testthat.r-lib.org/reference/test_that.html">test_that</a></span><span class="op">(</span><span class="st">'Basic tests'</span>, <span class="op">{</span></span>
253
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">make_negative</span><span class="op">(</span><span class="fl">42</span><span class="op">)</span>, <span class="op">-</span><span class="fl">42</span><span class="op">)</span></span>
254
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">make_negative</span><span class="op">(</span><span class="op">-</span><span class="fl">9</span><span class="op">)</span>, <span class="op">-</span><span class="fl">9</span><span class="op">)</span></span>
255
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">make_negative</span><span class="op">(</span><span class="fl">0</span><span class="op">)</span>, <span class="fl">0</span><span class="op">)</span></span>
256
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">make_negative</span><span class="op">(</span><span class="fl">1</span><span class="op">)</span>, <span class="op">-</span><span class="fl">1</span><span class="op">)</span></span>
257
+ <span> <span class="fu"><a href="https://testthat.r-lib.org/reference/equality-expectations.html">expect_equal</a></span><span class="op">(</span><span class="fu">make_negative</span><span class="op">(</span><span class="op">-</span><span class="fl">1</span><span class="op">)</span>, <span class="op">-</span><span class="fl">1</span><span class="op">)</span></span>
258
+ <span><span class="op">}</span><span class="op">)</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
259
+ <div class="cell-output cell-output-stdout">
260
+ <pre><code>## Test passed 🎉</code></pre>
261
+ </div>
262
+ </div>
263
+ <hr>
264
+ <p><strong>Supported by</strong></p>
265
+ <div class="quarto-figure quarto-figure-center">
266
+ <figure class="figure"><p><img src="new_starcore_logo.png" class="img-fluid figure-img"></p>
267
+ <figcaption>StarCore Analytics</figcaption></figure>
268
+ </div>
269
+
270
+
271
+
272
+ </main><!-- /main --><script id="quarto-html-after-body" type="application/javascript">
273
+ window.document.addEventListener("DOMContentLoaded", function (event) {
274
+ const toggleBodyColorMode = (bsSheetEl) => {
275
+ const mode = bsSheetEl.getAttribute("data-mode");
276
+ const bodyEl = window.document.querySelector("body");
277
+ if (mode === "dark") {
278
+ bodyEl.classList.add("quarto-dark");
279
+ bodyEl.classList.remove("quarto-light");
280
+ } else {
281
+ bodyEl.classList.add("quarto-light");
282
+ bodyEl.classList.remove("quarto-dark");
283
+ }
284
+ }
285
+ const toggleBodyColorPrimary = () => {
286
+ const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
287
+ if (bsSheetEl) {
288
+ toggleBodyColorMode(bsSheetEl);
289
+ }
290
+ }
291
+ toggleBodyColorPrimary();
292
+ const icon = "";
293
+ const anchorJS = new window.AnchorJS();
294
+ anchorJS.options = {
295
+ placement: 'right',
296
+ icon: icon
297
+ };
298
+ anchorJS.add('.anchored');
299
+ const isCodeAnnotation = (el) => {
300
+ for (const clz of el.classList) {
301
+ if (clz.startsWith('code-annotation-')) {
302
+ return true;
303
+ }
304
+ }
305
+ return false;
306
+ }
307
+ const onCopySuccess = function(e) {
308
+ // button target
309
+ const button = e.trigger;
310
+ // don't keep focus
311
+ button.blur();
312
+ // flash "checked"
313
+ button.classList.add('code-copy-button-checked');
314
+ var currentTitle = button.getAttribute("title");
315
+ button.setAttribute("title", "Copied!");
316
+ let tooltip;
317
+ if (window.bootstrap) {
318
+ button.setAttribute("data-bs-toggle", "tooltip");
319
+ button.setAttribute("data-bs-placement", "left");
320
+ button.setAttribute("data-bs-title", "Copied!");
321
+ tooltip = new bootstrap.Tooltip(button,
322
+ { trigger: "manual",
323
+ customClass: "code-copy-button-tooltip",
324
+ offset: [0, -8]});
325
+ tooltip.show();
326
+ }
327
+ setTimeout(function() {
328
+ if (tooltip) {
329
+ tooltip.hide();
330
+ button.removeAttribute("data-bs-title");
331
+ button.removeAttribute("data-bs-toggle");
332
+ button.removeAttribute("data-bs-placement");
333
+ }
334
+ button.setAttribute("title", currentTitle);
335
+ button.classList.remove('code-copy-button-checked');
336
+ }, 1000);
337
+ // clear code selection
338
+ e.clearSelection();
339
+ }
340
+ const getTextToCopy = function(trigger) {
341
+ const codeEl = trigger.previousElementSibling.cloneNode(true);
342
+ for (const childEl of codeEl.children) {
343
+ if (isCodeAnnotation(childEl)) {
344
+ childEl.remove();
345
+ }
346
+ }
347
+ return codeEl.innerText;
348
+ }
349
+ const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
350
+ text: getTextToCopy
351
+ });
352
+ clipboard.on('success', onCopySuccess);
353
+ if (window.document.getElementById('quarto-embedded-source-code-modal')) {
354
+ // For code content inside modals, clipBoardJS needs to be initialized with a container option
355
+ // TODO: Check when it could be a function (https://github.com/zenorocha/clipboard.js/issues/860)
356
+ const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
357
+ text: getTextToCopy,
358
+ container: window.document.getElementById('quarto-embedded-source-code-modal')
359
+ });
360
+ clipboardModal.on('success', onCopySuccess);
361
+ }
362
+ var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
363
+ var mailtoRegex = new RegExp(/^mailto:/);
364
+ var filterRegex = new RegExp("https:\/\/huggingface\.co\/spaces\/aephidayatuloh\/codewarschallenge\/");
365
+ var isInternal = (href) => {
366
+ return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
367
+ }
368
+ // Inspect non-navigation links and adorn them if external
369
+ var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
370
+ for (var i=0; i<links.length; i++) {
371
+ const link = links[i];
372
+ if (!isInternal(link.href)) {
373
+ // undo the damage that might have been done by quarto-nav.js in the case of
374
+ // links that we want to consider external
375
+ if (link.dataset.originalHref !== undefined) {
376
+ link.href = link.dataset.originalHref;
377
+ }
378
+ }
379
+ }
380
+ function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
381
+ const config = {
382
+ allowHTML: true,
383
+ maxWidth: 500,
384
+ delay: 100,
385
+ arrow: false,
386
+ appendTo: function(el) {
387
+ return el.parentElement;
388
+ },
389
+ interactive: true,
390
+ interactiveBorder: 10,
391
+ theme: 'quarto',
392
+ placement: 'bottom-start',
393
+ };
394
+ if (contentFn) {
395
+ config.content = contentFn;
396
+ }
397
+ if (onTriggerFn) {
398
+ config.onTrigger = onTriggerFn;
399
+ }
400
+ if (onUntriggerFn) {
401
+ config.onUntrigger = onUntriggerFn;
402
+ }
403
+ window.tippy(el, config);
404
+ }
405
+ const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
406
+ for (var i=0; i<noterefs.length; i++) {
407
+ const ref = noterefs[i];
408
+ tippyHover(ref, function() {
409
+ // use id or data attribute instead here
410
+ let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
411
+ try { href = new URL(href).hash; } catch {}
412
+ const id = href.replace(/^#\/?/, "");
413
+ const note = window.document.getElementById(id);
414
+ if (note) {
415
+ return note.innerHTML;
416
+ } else {
417
+ return "";
418
+ }
419
+ });
420
+ }
421
+ const xrefs = window.document.querySelectorAll('a.quarto-xref');
422
+ const processXRef = (id, note) => {
423
+ // Strip column container classes
424
+ const stripColumnClz = (el) => {
425
+ el.classList.remove("page-full", "page-columns");
426
+ if (el.children) {
427
+ for (const child of el.children) {
428
+ stripColumnClz(child);
429
+ }
430
+ }
431
+ }
432
+ stripColumnClz(note)
433
+ if (id === null || id.startsWith('sec-')) {
434
+ // Special case sections, only their first couple elements
435
+ const container = document.createElement("div");
436
+ if (note.children && note.children.length > 2) {
437
+ container.appendChild(note.children[0].cloneNode(true));
438
+ for (let i = 1; i < note.children.length; i++) {
439
+ const child = note.children[i];
440
+ if (child.tagName === "P" && child.innerText === "") {
441
+ continue;
442
+ } else {
443
+ container.appendChild(child.cloneNode(true));
444
+ break;
445
+ }
446
+ }
447
+ if (window.Quarto?.typesetMath) {
448
+ window.Quarto.typesetMath(container);
449
+ }
450
+ return container.innerHTML
451
+ } else {
452
+ if (window.Quarto?.typesetMath) {
453
+ window.Quarto.typesetMath(note);
454
+ }
455
+ return note.innerHTML;
456
+ }
457
+ } else {
458
+ // Remove any anchor links if they are present
459
+ const anchorLink = note.querySelector('a.anchorjs-link');
460
+ if (anchorLink) {
461
+ anchorLink.remove();
462
+ }
463
+ if (window.Quarto?.typesetMath) {
464
+ window.Quarto.typesetMath(note);
465
+ }
466
+ // TODO in 1.5, we should make sure this works without a callout special case
467
+ if (note.classList.contains("callout")) {
468
+ return note.outerHTML;
469
+ } else {
470
+ return note.innerHTML;
471
+ }
472
+ }
473
+ }
474
+ for (var i=0; i<xrefs.length; i++) {
475
+ const xref = xrefs[i];
476
+ tippyHover(xref, undefined, function(instance) {
477
+ instance.disable();
478
+ let url = xref.getAttribute('href');
479
+ let hash = undefined;
480
+ if (url.startsWith('#')) {
481
+ hash = url;
482
+ } else {
483
+ try { hash = new URL(url).hash; } catch {}
484
+ }
485
+ if (hash) {
486
+ const id = hash.replace(/^#\/?/, "");
487
+ const note = window.document.getElementById(id);
488
+ if (note !== null) {
489
+ try {
490
+ const html = processXRef(id, note.cloneNode(true));
491
+ instance.setContent(html);
492
+ } finally {
493
+ instance.enable();
494
+ instance.show();
495
+ }
496
+ } else {
497
+ // See if we can fetch this
498
+ fetch(url.split('#')[0])
499
+ .then(res => res.text())
500
+ .then(html => {
501
+ const parser = new DOMParser();
502
+ const htmlDoc = parser.parseFromString(html, "text/html");
503
+ const note = htmlDoc.getElementById(id);
504
+ if (note !== null) {
505
+ const html = processXRef(id, note);
506
+ instance.setContent(html);
507
+ }
508
+ }).finally(() => {
509
+ instance.enable();
510
+ instance.show();
511
+ });
512
+ }
513
+ } else {
514
+ // See if we can fetch a full url (with no hash to target)
515
+ // This is a special case and we should probably do some content thinning / targeting
516
+ fetch(url)
517
+ .then(res => res.text())
518
+ .then(html => {
519
+ const parser = new DOMParser();
520
+ const htmlDoc = parser.parseFromString(html, "text/html");
521
+ const note = htmlDoc.querySelector('main.content');
522
+ if (note !== null) {
523
+ // This should only happen for chapter cross references
524
+ // (since there is no id in the URL)
525
+ // remove the first header
526
+ if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
527
+ note.children[0].remove();
528
+ }
529
+ const html = processXRef(null, note);
530
+ instance.setContent(html);
531
+ }
532
+ }).finally(() => {
533
+ instance.enable();
534
+ instance.show();
535
+ });
536
+ }
537
+ }, function(instance) {
538
+ });
539
+ }
540
+ let selectedAnnoteEl;
541
+ const selectorForAnnotation = ( cell, annotation) => {
542
+ let cellAttr = 'data-code-cell="' + cell + '"';
543
+ let lineAttr = 'data-code-annotation="' + annotation + '"';
544
+ const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
545
+ return selector;
546
+ }
547
+ const selectCodeLines = (annoteEl) => {
548
+ const doc = window.document;
549
+ const targetCell = annoteEl.getAttribute("data-target-cell");
550
+ const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
551
+ const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
552
+ const lines = annoteSpan.getAttribute("data-code-lines").split(",");
553
+ const lineIds = lines.map((line) => {
554
+ return targetCell + "-" + line;
555
+ })
556
+ let top = null;
557
+ let height = null;
558
+ let parent = null;
559
+ if (lineIds.length > 0) {
560
+ //compute the position of the single el (top and bottom and make a div)
561
+ const el = window.document.getElementById(lineIds[0]);
562
+ top = el.offsetTop;
563
+ height = el.offsetHeight;
564
+ parent = el.parentElement.parentElement;
565
+ if (lineIds.length > 1) {
566
+ const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
567
+ const bottom = lastEl.offsetTop + lastEl.offsetHeight;
568
+ height = bottom - top;
569
+ }
570
+ if (top !== null && height !== null && parent !== null) {
571
+ // cook up a div (if necessary) and position it
572
+ let div = window.document.getElementById("code-annotation-line-highlight");
573
+ if (div === null) {
574
+ div = window.document.createElement("div");
575
+ div.setAttribute("id", "code-annotation-line-highlight");
576
+ div.style.position = 'absolute';
577
+ parent.appendChild(div);
578
+ }
579
+ div.style.top = top - 2 + "px";
580
+ div.style.height = height + 4 + "px";
581
+ div.style.left = 0;
582
+ let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
583
+ if (gutterDiv === null) {
584
+ gutterDiv = window.document.createElement("div");
585
+ gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
586
+ gutterDiv.style.position = 'absolute';
587
+ const codeCell = window.document.getElementById(targetCell);
588
+ const gutter = codeCell.querySelector('.code-annotation-gutter');
589
+ gutter.appendChild(gutterDiv);
590
+ }
591
+ gutterDiv.style.top = top - 2 + "px";
592
+ gutterDiv.style.height = height + 4 + "px";
593
+ }
594
+ selectedAnnoteEl = annoteEl;
595
+ }
596
+ };
597
+ const unselectCodeLines = () => {
598
+ const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
599
+ elementsIds.forEach((elId) => {
600
+ const div = window.document.getElementById(elId);
601
+ if (div) {
602
+ div.remove();
603
+ }
604
+ });
605
+ selectedAnnoteEl = undefined;
606
+ };
607
+ // Handle positioning of the toggle
608
+ window.addEventListener(
609
+ "resize",
610
+ throttle(() => {
611
+ elRect = undefined;
612
+ if (selectedAnnoteEl) {
613
+ selectCodeLines(selectedAnnoteEl);
614
+ }
615
+ }, 10)
616
+ );
617
+ function throttle(fn, ms) {
618
+ let throttle = false;
619
+ let timer;
620
+ return (...args) => {
621
+ if(!throttle) { // first call gets through
622
+ fn.apply(this, args);
623
+ throttle = true;
624
+ } else { // all the others get throttled
625
+ if(timer) clearTimeout(timer); // cancel #2
626
+ timer = setTimeout(() => {
627
+ fn.apply(this, args);
628
+ timer = throttle = false;
629
+ }, ms);
630
+ }
631
+ };
632
+ }
633
+ // Attach click handler to the DT
634
+ const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
635
+ for (const annoteDlNode of annoteDls) {
636
+ annoteDlNode.addEventListener('click', (event) => {
637
+ const clickedEl = event.target;
638
+ if (clickedEl !== selectedAnnoteEl) {
639
+ unselectCodeLines();
640
+ const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
641
+ if (activeEl) {
642
+ activeEl.classList.remove('code-annotation-active');
643
+ }
644
+ selectCodeLines(clickedEl);
645
+ clickedEl.classList.add('code-annotation-active');
646
+ } else {
647
+ // Unselect the line
648
+ unselectCodeLines();
649
+ clickedEl.classList.remove('code-annotation-active');
650
+ }
651
+ });
652
+ }
653
+ const findCites = (el) => {
654
+ const parentEl = el.parentElement;
655
+ if (parentEl) {
656
+ const cites = parentEl.dataset.cites;
657
+ if (cites) {
658
+ return {
659
+ el,
660
+ cites: cites.split(' ')
661
+ };
662
+ } else {
663
+ return findCites(el.parentElement)
664
+ }
665
+ } else {
666
+ return undefined;
667
+ }
668
+ };
669
+ var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
670
+ for (var i=0; i<bibliorefs.length; i++) {
671
+ const ref = bibliorefs[i];
672
+ const citeInfo = findCites(ref);
673
+ if (citeInfo) {
674
+ tippyHover(citeInfo.el, function() {
675
+ var popup = window.document.createElement('div');
676
+ citeInfo.cites.forEach(function(cite) {
677
+ var citeDiv = window.document.createElement('div');
678
+ citeDiv.classList.add('hanging-indent');
679
+ citeDiv.classList.add('csl-entry');
680
+ var biblioDiv = window.document.getElementById('ref-' + cite);
681
+ if (biblioDiv) {
682
+ citeDiv.innerHTML = biblioDiv.innerHTML;
683
+ }
684
+ popup.appendChild(citeDiv);
685
+ });
686
+ return popup.innerHTML;
687
+ });
688
+ }
689
+ }
690
+ });
691
+ </script><nav class="page-navigation"><div class="nav-page nav-page-previous">
692
+ <a href="./cw0004reducegrow.html" class="pagination-link" aria-label="Beginner - Reduce but Grow!">
693
+ <i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow!</span></span>
694
+ </a>
695
+ </div>
696
+ <div class="nav-page nav-page-next">
697
+ </div>
698
+ </nav>
699
+ </div> <!-- /content -->
700
+
701
+
702
+
703
+ </body></html>
index.html CHANGED
@@ -1,19 +1,655 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
3
+
4
+ <meta charset="utf-8">
5
+ <meta name="generator" content="quarto-1.5.53">
6
+
7
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
8
+
9
+ <meta name="author" content="Aep Hidayatuloh">
10
+
11
+ <title>Codewars Challenge</title>
12
+ <style>
13
+ code{white-space: pre-wrap;}
14
+ span.smallcaps{font-variant: small-caps;}
15
+ div.columns{display: flex; gap: min(4vw, 1.5em);}
16
+ div.column{flex: auto; overflow-x: auto;}
17
+ div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
18
+ ul.task-list{list-style: none;}
19
+ ul.task-list li input[type="checkbox"] {
20
+ width: 0.8em;
21
+ margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
22
+ vertical-align: middle;
23
+ }
24
+ </style>
25
+
26
+
27
+ <script src="site_libs/quarto-nav/quarto-nav.js"></script>
28
+ <script src="site_libs/quarto-nav/headroom.min.js"></script>
29
+ <script src="site_libs/clipboard/clipboard.min.js"></script>
30
+ <script src="site_libs/quarto-search/autocomplete.umd.js"></script>
31
+ <script src="site_libs/quarto-search/fuse.min.js"></script>
32
+ <script src="site_libs/quarto-search/quarto-search.js"></script>
33
+ <meta name="quarto:offset" content="./">
34
+ <link href="./cw0001evenodd.html" rel="next">
35
+ <script src="site_libs/quarto-html/quarto.js"></script>
36
+ <script src="site_libs/quarto-html/popper.min.js"></script>
37
+ <script src="site_libs/quarto-html/tippy.umd.min.js"></script>
38
+ <script src="site_libs/quarto-html/anchor.min.js"></script>
39
+ <link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
40
+ <link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
41
+ <script src="site_libs/bootstrap/bootstrap.min.js"></script>
42
+ <link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
43
+ <link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
44
+ <script id="quarto-search-options" type="application/json">{
45
+ "location": "sidebar",
46
+ "copy-button": false,
47
+ "collapse-after": 3,
48
+ "panel-placement": "start",
49
+ "type": "textbox",
50
+ "limit": 50,
51
+ "keyboard-shortcut": [
52
+ "f",
53
+ "/",
54
+ "s"
55
+ ],
56
+ "show-item-context": false,
57
+ "language": {
58
+ "search-no-results-text": "No results",
59
+ "search-matching-documents-text": "matching documents",
60
+ "search-copy-link-title": "Copy link to search",
61
+ "search-hide-matches-text": "Hide additional matches",
62
+ "search-more-match-text": "more match in this document",
63
+ "search-more-matches-text": "more matches in this document",
64
+ "search-clear-button-title": "Clear",
65
+ "search-text-placeholder": "",
66
+ "search-detached-cancel-button-title": "Cancel",
67
+ "search-submit-button-title": "Submit",
68
+ "search-label": "Search"
69
+ }
70
+ }</script>
71
+
72
+
73
+ <link rel="stylesheet" href="style.css">
74
+ <meta name="twitter:title" content="Codewars Challenge">
75
+ <meta name="twitter:description" content="">
76
+ <meta name="twitter:card" content="summary">
77
+ </head>
78
+
79
+ <body class="nav-sidebar floating">
80
+
81
+ <div id="quarto-search-results"></div>
82
+ <header id="quarto-header" class="headroom fixed-top">
83
+ <nav class="quarto-secondary-nav">
84
+ <div class="container-fluid d-flex">
85
+ <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" role="button" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
86
+ <i class="bi bi-layout-text-sidebar-reverse"></i>
87
+ </button>
88
+ <nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./index.html">Pengantar</a></li></ol></nav>
89
+ <a class="flex-grow-1" role="navigation" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
90
+ </a>
91
+ <button type="button" class="btn quarto-search-button" aria-label="Search" onclick="window.quartoOpenSearch();">
92
+ <i class="bi bi-search"></i>
93
+ </button>
94
+ </div>
95
+ </nav>
96
+ </header>
97
+ <!-- content -->
98
+ <div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
99
+ <!-- sidebar -->
100
+ <nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal quarto-sidebar-collapse-item sidebar-navigation floating overflow-auto">
101
+ <div class="pt-lg-2 mt-2 text-left sidebar-header">
102
+ <div class="sidebar-title mb-0 py-0">
103
+ <a href="./">Codewars Challenge</a>
104
+ <div class="sidebar-tools-main">
105
+ <a href="https://huggingface.co/spaces/aephidayatuloh/codewarschallenge/tree/main" title="Source Code" class="quarto-navigation-tool px-1" aria-label="Source Code"><i class="bi bi-git"></i></a>
106
+ </div>
107
+ </div>
108
+ </div>
109
+ <div class="mt-2 flex-shrink-0 align-items-center">
110
+ <div class="sidebar-search">
111
+ <div id="quarto-search" class="" title="Search"></div>
112
+ </div>
113
+ </div>
114
+ <div class="sidebar-menu-container">
115
+ <ul class="list-unstyled mt-1">
116
+ <li class="sidebar-item">
117
+ <div class="sidebar-item-container">
118
+ <a href="./index.html" class="sidebar-item-text sidebar-link active">
119
+ <span class="menu-text">Pengantar</span></a>
120
+ </div>
121
+ </li>
122
+ <li class="sidebar-item sidebar-item-section">
123
+ <div class="sidebar-item-container">
124
+ <a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="false">
125
+ <span class="menu-text">2025</span></a>
126
+ <a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" role="navigation" aria-expanded="false" aria-label="Toggle section">
127
+ <i class="bi bi-chevron-right ms-2"></i>
128
+ </a>
129
+ </div>
130
+ <ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 ">
131
+ <li class="sidebar-item">
132
+ <div class="sidebar-item-container">
133
+ <a href="./cw0001evenodd.html" class="sidebar-item-text sidebar-link">
134
+ <span class="menu-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span></span></a>
135
+ </div>
136
+ </li>
137
+ <li class="sidebar-item">
138
+ <div class="sidebar-item-container">
139
+ <a href="./cw0002multiply.html" class="sidebar-item-text sidebar-link">
140
+ <span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span></span></a>
141
+ </div>
142
+ </li>
143
+ <li class="sidebar-item">
144
+ <div class="sidebar-item-container">
145
+ <a href="./cw0003countsheep.html" class="sidebar-item-text sidebar-link">
146
+ <span class="menu-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Count Sheep</span></span></a>
147
+ </div>
148
+ </li>
149
+ <li class="sidebar-item">
150
+ <div class="sidebar-item-container">
151
+ <a href="./cw0004reducegrow.html" class="sidebar-item-text sidebar-link">
152
+ <span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow!</span></span></a>
153
+ </div>
154
+ </li>
155
+ <li class="sidebar-item">
156
+ <div class="sidebar-item-container">
157
+ <a href="./cw0005makenegative.html" class="sidebar-item-text sidebar-link">
158
+ <span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Return Negative</span></span></a>
159
+ </div>
160
+ </li>
161
+ </ul>
162
+ </li>
163
+ </ul>
164
+ </div>
165
+ </nav>
166
+ <div id="quarto-sidebar-glass" class="quarto-sidebar-collapse-item" data-bs-toggle="collapse" data-bs-target=".quarto-sidebar-collapse-item"></div>
167
+ <!-- margin-sidebar -->
168
+ <div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
169
+ <nav id="TOC" role="doc-toc" class="toc-active" data-toc-expanded="99">
170
+ <h2 id="toc-title">Table of contents</h2>
171
+
172
+ <ul>
173
+ <li><a href="#pengantar" id="toc-pengantar" class="nav-link active" data-scroll-target="#pengantar">Pengantar</a></li>
174
+ </ul>
175
+ </nav>
176
+ </div>
177
+ <!-- main -->
178
+ <main class="content" id="quarto-document-content">
179
+
180
+ <header id="title-block-header" class="quarto-title-block default">
181
+ <div class="quarto-title">
182
+ <h1 class="title">Codewars Challenge</h1>
183
+ </div>
184
+
185
+
186
+
187
+ <div class="quarto-title-meta">
188
+
189
+ <div>
190
+ <div class="quarto-title-meta-heading">Author</div>
191
+ <div class="quarto-title-meta-contents">
192
+ <p>Aep Hidayatuloh <a href="mailto:aephidayatuloh.mail@gmail.com" class="quarto-title-author-email"><i class="bi bi-envelope"></i></a> </p>
193
+ </div>
194
+ </div>
195
+
196
+ <div>
197
+ <div class="quarto-title-meta-heading">Published</div>
198
+ <div class="quarto-title-meta-contents">
199
+ <p class="date">Last Updated on 01 February, 2025</p>
200
+ </div>
201
+ </div>
202
+
203
+
204
+ </div>
205
+
206
+
207
+
208
+ </header>
209
+
210
+
211
+ <h1 class="unnumbered" id="pengantar">Pengantar</h1>
212
+ <p>Buku ini adalah catatan penyelesaian dalam mengerjakan tantangan-tantangan logika dan pemrograman Codewars menggunakan R/Python dan RStudio/Positron.</p>
213
+ <div class="logo-icon">
214
+ <p><img src="R.png" class="img-fluid"> <img src="python.png" class="img-fluid"> <img src="RStudio-icon.png" class="img-fluid"> <img src="positron.png" class="img-fluid"></p>
215
+ </div>
216
+ <p>Hal ini terinspirasi dari kegiatan di YouTube nya Pak Sandhika Galih WPU.</p>
217
+
218
+
219
+
220
+ </main> <!-- /main -->
221
+ <script id="quarto-html-after-body" type="application/javascript">
222
+ window.document.addEventListener("DOMContentLoaded", function (event) {
223
+ const toggleBodyColorMode = (bsSheetEl) => {
224
+ const mode = bsSheetEl.getAttribute("data-mode");
225
+ const bodyEl = window.document.querySelector("body");
226
+ if (mode === "dark") {
227
+ bodyEl.classList.add("quarto-dark");
228
+ bodyEl.classList.remove("quarto-light");
229
+ } else {
230
+ bodyEl.classList.add("quarto-light");
231
+ bodyEl.classList.remove("quarto-dark");
232
+ }
233
+ }
234
+ const toggleBodyColorPrimary = () => {
235
+ const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
236
+ if (bsSheetEl) {
237
+ toggleBodyColorMode(bsSheetEl);
238
+ }
239
+ }
240
+ toggleBodyColorPrimary();
241
+ const icon = "";
242
+ const anchorJS = new window.AnchorJS();
243
+ anchorJS.options = {
244
+ placement: 'right',
245
+ icon: icon
246
+ };
247
+ anchorJS.add('.anchored');
248
+ const isCodeAnnotation = (el) => {
249
+ for (const clz of el.classList) {
250
+ if (clz.startsWith('code-annotation-')) {
251
+ return true;
252
+ }
253
+ }
254
+ return false;
255
+ }
256
+ const onCopySuccess = function(e) {
257
+ // button target
258
+ const button = e.trigger;
259
+ // don't keep focus
260
+ button.blur();
261
+ // flash "checked"
262
+ button.classList.add('code-copy-button-checked');
263
+ var currentTitle = button.getAttribute("title");
264
+ button.setAttribute("title", "Copied!");
265
+ let tooltip;
266
+ if (window.bootstrap) {
267
+ button.setAttribute("data-bs-toggle", "tooltip");
268
+ button.setAttribute("data-bs-placement", "left");
269
+ button.setAttribute("data-bs-title", "Copied!");
270
+ tooltip = new bootstrap.Tooltip(button,
271
+ { trigger: "manual",
272
+ customClass: "code-copy-button-tooltip",
273
+ offset: [0, -8]});
274
+ tooltip.show();
275
+ }
276
+ setTimeout(function() {
277
+ if (tooltip) {
278
+ tooltip.hide();
279
+ button.removeAttribute("data-bs-title");
280
+ button.removeAttribute("data-bs-toggle");
281
+ button.removeAttribute("data-bs-placement");
282
+ }
283
+ button.setAttribute("title", currentTitle);
284
+ button.classList.remove('code-copy-button-checked');
285
+ }, 1000);
286
+ // clear code selection
287
+ e.clearSelection();
288
+ }
289
+ const getTextToCopy = function(trigger) {
290
+ const codeEl = trigger.previousElementSibling.cloneNode(true);
291
+ for (const childEl of codeEl.children) {
292
+ if (isCodeAnnotation(childEl)) {
293
+ childEl.remove();
294
+ }
295
+ }
296
+ return codeEl.innerText;
297
+ }
298
+ const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
299
+ text: getTextToCopy
300
+ });
301
+ clipboard.on('success', onCopySuccess);
302
+ if (window.document.getElementById('quarto-embedded-source-code-modal')) {
303
+ // For code content inside modals, clipBoardJS needs to be initialized with a container option
304
+ // TODO: Check when it could be a function (https://github.com/zenorocha/clipboard.js/issues/860)
305
+ const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
306
+ text: getTextToCopy,
307
+ container: window.document.getElementById('quarto-embedded-source-code-modal')
308
+ });
309
+ clipboardModal.on('success', onCopySuccess);
310
+ }
311
+ var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
312
+ var mailtoRegex = new RegExp(/^mailto:/);
313
+ var filterRegex = new RegExp("https:\/\/huggingface\.co\/spaces\/aephidayatuloh\/codewarschallenge\/");
314
+ var isInternal = (href) => {
315
+ return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
316
+ }
317
+ // Inspect non-navigation links and adorn them if external
318
+ var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
319
+ for (var i=0; i<links.length; i++) {
320
+ const link = links[i];
321
+ if (!isInternal(link.href)) {
322
+ // undo the damage that might have been done by quarto-nav.js in the case of
323
+ // links that we want to consider external
324
+ if (link.dataset.originalHref !== undefined) {
325
+ link.href = link.dataset.originalHref;
326
+ }
327
+ }
328
+ }
329
+ function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
330
+ const config = {
331
+ allowHTML: true,
332
+ maxWidth: 500,
333
+ delay: 100,
334
+ arrow: false,
335
+ appendTo: function(el) {
336
+ return el.parentElement;
337
+ },
338
+ interactive: true,
339
+ interactiveBorder: 10,
340
+ theme: 'quarto',
341
+ placement: 'bottom-start',
342
+ };
343
+ if (contentFn) {
344
+ config.content = contentFn;
345
+ }
346
+ if (onTriggerFn) {
347
+ config.onTrigger = onTriggerFn;
348
+ }
349
+ if (onUntriggerFn) {
350
+ config.onUntrigger = onUntriggerFn;
351
+ }
352
+ window.tippy(el, config);
353
+ }
354
+ const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
355
+ for (var i=0; i<noterefs.length; i++) {
356
+ const ref = noterefs[i];
357
+ tippyHover(ref, function() {
358
+ // use id or data attribute instead here
359
+ let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
360
+ try { href = new URL(href).hash; } catch {}
361
+ const id = href.replace(/^#\/?/, "");
362
+ const note = window.document.getElementById(id);
363
+ if (note) {
364
+ return note.innerHTML;
365
+ } else {
366
+ return "";
367
+ }
368
+ });
369
+ }
370
+ const xrefs = window.document.querySelectorAll('a.quarto-xref');
371
+ const processXRef = (id, note) => {
372
+ // Strip column container classes
373
+ const stripColumnClz = (el) => {
374
+ el.classList.remove("page-full", "page-columns");
375
+ if (el.children) {
376
+ for (const child of el.children) {
377
+ stripColumnClz(child);
378
+ }
379
+ }
380
+ }
381
+ stripColumnClz(note)
382
+ if (id === null || id.startsWith('sec-')) {
383
+ // Special case sections, only their first couple elements
384
+ const container = document.createElement("div");
385
+ if (note.children && note.children.length > 2) {
386
+ container.appendChild(note.children[0].cloneNode(true));
387
+ for (let i = 1; i < note.children.length; i++) {
388
+ const child = note.children[i];
389
+ if (child.tagName === "P" && child.innerText === "") {
390
+ continue;
391
+ } else {
392
+ container.appendChild(child.cloneNode(true));
393
+ break;
394
+ }
395
+ }
396
+ if (window.Quarto?.typesetMath) {
397
+ window.Quarto.typesetMath(container);
398
+ }
399
+ return container.innerHTML
400
+ } else {
401
+ if (window.Quarto?.typesetMath) {
402
+ window.Quarto.typesetMath(note);
403
+ }
404
+ return note.innerHTML;
405
+ }
406
+ } else {
407
+ // Remove any anchor links if they are present
408
+ const anchorLink = note.querySelector('a.anchorjs-link');
409
+ if (anchorLink) {
410
+ anchorLink.remove();
411
+ }
412
+ if (window.Quarto?.typesetMath) {
413
+ window.Quarto.typesetMath(note);
414
+ }
415
+ // TODO in 1.5, we should make sure this works without a callout special case
416
+ if (note.classList.contains("callout")) {
417
+ return note.outerHTML;
418
+ } else {
419
+ return note.innerHTML;
420
+ }
421
+ }
422
+ }
423
+ for (var i=0; i<xrefs.length; i++) {
424
+ const xref = xrefs[i];
425
+ tippyHover(xref, undefined, function(instance) {
426
+ instance.disable();
427
+ let url = xref.getAttribute('href');
428
+ let hash = undefined;
429
+ if (url.startsWith('#')) {
430
+ hash = url;
431
+ } else {
432
+ try { hash = new URL(url).hash; } catch {}
433
+ }
434
+ if (hash) {
435
+ const id = hash.replace(/^#\/?/, "");
436
+ const note = window.document.getElementById(id);
437
+ if (note !== null) {
438
+ try {
439
+ const html = processXRef(id, note.cloneNode(true));
440
+ instance.setContent(html);
441
+ } finally {
442
+ instance.enable();
443
+ instance.show();
444
+ }
445
+ } else {
446
+ // See if we can fetch this
447
+ fetch(url.split('#')[0])
448
+ .then(res => res.text())
449
+ .then(html => {
450
+ const parser = new DOMParser();
451
+ const htmlDoc = parser.parseFromString(html, "text/html");
452
+ const note = htmlDoc.getElementById(id);
453
+ if (note !== null) {
454
+ const html = processXRef(id, note);
455
+ instance.setContent(html);
456
+ }
457
+ }).finally(() => {
458
+ instance.enable();
459
+ instance.show();
460
+ });
461
+ }
462
+ } else {
463
+ // See if we can fetch a full url (with no hash to target)
464
+ // This is a special case and we should probably do some content thinning / targeting
465
+ fetch(url)
466
+ .then(res => res.text())
467
+ .then(html => {
468
+ const parser = new DOMParser();
469
+ const htmlDoc = parser.parseFromString(html, "text/html");
470
+ const note = htmlDoc.querySelector('main.content');
471
+ if (note !== null) {
472
+ // This should only happen for chapter cross references
473
+ // (since there is no id in the URL)
474
+ // remove the first header
475
+ if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
476
+ note.children[0].remove();
477
+ }
478
+ const html = processXRef(null, note);
479
+ instance.setContent(html);
480
+ }
481
+ }).finally(() => {
482
+ instance.enable();
483
+ instance.show();
484
+ });
485
+ }
486
+ }, function(instance) {
487
+ });
488
+ }
489
+ let selectedAnnoteEl;
490
+ const selectorForAnnotation = ( cell, annotation) => {
491
+ let cellAttr = 'data-code-cell="' + cell + '"';
492
+ let lineAttr = 'data-code-annotation="' + annotation + '"';
493
+ const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
494
+ return selector;
495
+ }
496
+ const selectCodeLines = (annoteEl) => {
497
+ const doc = window.document;
498
+ const targetCell = annoteEl.getAttribute("data-target-cell");
499
+ const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
500
+ const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
501
+ const lines = annoteSpan.getAttribute("data-code-lines").split(",");
502
+ const lineIds = lines.map((line) => {
503
+ return targetCell + "-" + line;
504
+ })
505
+ let top = null;
506
+ let height = null;
507
+ let parent = null;
508
+ if (lineIds.length > 0) {
509
+ //compute the position of the single el (top and bottom and make a div)
510
+ const el = window.document.getElementById(lineIds[0]);
511
+ top = el.offsetTop;
512
+ height = el.offsetHeight;
513
+ parent = el.parentElement.parentElement;
514
+ if (lineIds.length > 1) {
515
+ const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
516
+ const bottom = lastEl.offsetTop + lastEl.offsetHeight;
517
+ height = bottom - top;
518
+ }
519
+ if (top !== null && height !== null && parent !== null) {
520
+ // cook up a div (if necessary) and position it
521
+ let div = window.document.getElementById("code-annotation-line-highlight");
522
+ if (div === null) {
523
+ div = window.document.createElement("div");
524
+ div.setAttribute("id", "code-annotation-line-highlight");
525
+ div.style.position = 'absolute';
526
+ parent.appendChild(div);
527
+ }
528
+ div.style.top = top - 2 + "px";
529
+ div.style.height = height + 4 + "px";
530
+ div.style.left = 0;
531
+ let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
532
+ if (gutterDiv === null) {
533
+ gutterDiv = window.document.createElement("div");
534
+ gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
535
+ gutterDiv.style.position = 'absolute';
536
+ const codeCell = window.document.getElementById(targetCell);
537
+ const gutter = codeCell.querySelector('.code-annotation-gutter');
538
+ gutter.appendChild(gutterDiv);
539
+ }
540
+ gutterDiv.style.top = top - 2 + "px";
541
+ gutterDiv.style.height = height + 4 + "px";
542
+ }
543
+ selectedAnnoteEl = annoteEl;
544
+ }
545
+ };
546
+ const unselectCodeLines = () => {
547
+ const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
548
+ elementsIds.forEach((elId) => {
549
+ const div = window.document.getElementById(elId);
550
+ if (div) {
551
+ div.remove();
552
+ }
553
+ });
554
+ selectedAnnoteEl = undefined;
555
+ };
556
+ // Handle positioning of the toggle
557
+ window.addEventListener(
558
+ "resize",
559
+ throttle(() => {
560
+ elRect = undefined;
561
+ if (selectedAnnoteEl) {
562
+ selectCodeLines(selectedAnnoteEl);
563
+ }
564
+ }, 10)
565
+ );
566
+ function throttle(fn, ms) {
567
+ let throttle = false;
568
+ let timer;
569
+ return (...args) => {
570
+ if(!throttle) { // first call gets through
571
+ fn.apply(this, args);
572
+ throttle = true;
573
+ } else { // all the others get throttled
574
+ if(timer) clearTimeout(timer); // cancel #2
575
+ timer = setTimeout(() => {
576
+ fn.apply(this, args);
577
+ timer = throttle = false;
578
+ }, ms);
579
+ }
580
+ };
581
+ }
582
+ // Attach click handler to the DT
583
+ const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
584
+ for (const annoteDlNode of annoteDls) {
585
+ annoteDlNode.addEventListener('click', (event) => {
586
+ const clickedEl = event.target;
587
+ if (clickedEl !== selectedAnnoteEl) {
588
+ unselectCodeLines();
589
+ const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
590
+ if (activeEl) {
591
+ activeEl.classList.remove('code-annotation-active');
592
+ }
593
+ selectCodeLines(clickedEl);
594
+ clickedEl.classList.add('code-annotation-active');
595
+ } else {
596
+ // Unselect the line
597
+ unselectCodeLines();
598
+ clickedEl.classList.remove('code-annotation-active');
599
+ }
600
+ });
601
+ }
602
+ const findCites = (el) => {
603
+ const parentEl = el.parentElement;
604
+ if (parentEl) {
605
+ const cites = parentEl.dataset.cites;
606
+ if (cites) {
607
+ return {
608
+ el,
609
+ cites: cites.split(' ')
610
+ };
611
+ } else {
612
+ return findCites(el.parentElement)
613
+ }
614
+ } else {
615
+ return undefined;
616
+ }
617
+ };
618
+ var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
619
+ for (var i=0; i<bibliorefs.length; i++) {
620
+ const ref = bibliorefs[i];
621
+ const citeInfo = findCites(ref);
622
+ if (citeInfo) {
623
+ tippyHover(citeInfo.el, function() {
624
+ var popup = window.document.createElement('div');
625
+ citeInfo.cites.forEach(function(cite) {
626
+ var citeDiv = window.document.createElement('div');
627
+ citeDiv.classList.add('hanging-indent');
628
+ citeDiv.classList.add('csl-entry');
629
+ var biblioDiv = window.document.getElementById('ref-' + cite);
630
+ if (biblioDiv) {
631
+ citeDiv.innerHTML = biblioDiv.innerHTML;
632
+ }
633
+ popup.appendChild(citeDiv);
634
+ });
635
+ return popup.innerHTML;
636
+ });
637
+ }
638
+ }
639
+ });
640
+ </script>
641
+ <nav class="page-navigation">
642
+ <div class="nav-page nav-page-previous">
643
+ </div>
644
+ <div class="nav-page nav-page-next">
645
+ <a href="./cw0001evenodd.html" class="pagination-link" aria-label="Even or Odd">
646
+ <span class="nav-page-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span></span> <i class="bi bi-arrow-right-short"></i>
647
+ </a>
648
+ </div>
649
+ </nav>
650
+ </div> <!-- /content -->
651
+
652
+
653
+
654
+
655
+ </body></html>
new_starcore_logo.png ADDED
positron.png ADDED
python.png ADDED

Git LFS Details

  • SHA256: 36da3591428f2414328dd112bc6ddeb272e24c533eace8c5159842704fa00696
  • Pointer size: 131 Bytes
  • Size of remote file: 181 kB
robots.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Sitemap: https://huggingface.co/spaces/aephidayatuloh/codewarschallenge/sitemap.xml
search.json ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "objectID": "index.html",
4
+ "href": "index.html",
5
+ "title": "Codewars Challenge",
6
+ "section": "",
7
+ "text": "Pengantar\nBuku ini adalah catatan penyelesaian dalam mengerjakan tantangan-tantangan logika dan pemrograman Codewars menggunakan R/Python dan RStudio/Positron.\n\n \n\nHal ini terinspirasi dari kegiatan di YouTube nya Pak Sandhika Galih WPU.",
8
+ "crumbs": [
9
+ "Pengantar"
10
+ ]
11
+ },
12
+ {
13
+ "objectID": "cw0001evenodd.html",
14
+ "href": "cw0001evenodd.html",
15
+ "title": "\n1  Even or Odd\n",
16
+ "section": "",
17
+ "text": "8Kyu Tantangan #1/366 - 01 Feb 2025\nhttps://www.codewars.com/kata/53da3dbb4a5168369a0000fe\n\n1.1 Instruction\n\nCreate a function that takes an integer as an argument and returns \"Even\" for even numbers or \"Odd\" for odd numbers.\n\n\n1.2 YouTube Video\n\n\n1.3 Solution Code\nSolusi bar-bar\n\neven_or_odd &lt;- function(n) {\n ifelse(abs(n/2 - as.integer(n/2)) == 0.5, \"Odd\", \"Even\")\n}\n\nSolusi simple\n\neven_or_odd &lt;- function(n) {\n # %% operator modulo\n ifelse(n %% 2 == 1, \"Odd\", \"Even\")\n}\n\n\neven_or_odd &lt;- function(n) c(\"Even\", \"Odd\")[n %% 2 + 1]\n\n\n1.4 Test\n\nlibrary(testthat)\ntest_that('even_or_odd(1) returns \"Odd\"', {\n expect_equal(even_or_odd(1), \"Odd\")\n})\n\n## Test passed 🎉\n\ntest_that('even_or_odd(2) returns \"Even\"', {\n expect_equal(even_or_odd(2), \"Even\")\n})\n\n## Test passed 🥳\n\ntest_that('even_or_odd(0) returns \"Even\"', {\n expect_equal(even_or_odd(0), \"Even\")\n})\n\n## Test passed 😸\n\ntest_that('even_or_odd(-1) returns \"Odd\"', {\n expect_equal(even_or_odd(-1), \"Odd\")\n})\n\n## Test passed 🎉\n\ntest_that('even_or_odd(-2) returns \"Even\"', {\n expect_equal(even_or_odd(-2), \"Even\")\n})\n\n## Test passed 🎊\n\n\n\nSupported by\n\n\nStarCore Analytics",
18
+ "crumbs": [
19
+ "2025",
20
+ "<span class='chapter-number'>1</span>  <span class='chapter-title'>Even or Odd</span>"
21
+ ]
22
+ },
23
+ {
24
+ "objectID": "cw0002multiply.html",
25
+ "href": "cw0002multiply.html",
26
+ "title": "\n2  Multiply\n",
27
+ "section": "",
28
+ "text": "8Kyu Tantangan #2/366 - 02 Feb 2025\nhttps://www.codewars.com/kata/50654ddff44f800200000004\n\n2.1 Instruction\n\nThis code does not execute properly. Try to figure out why.\n\n\nmul &lt;- function(a, b) {\n a * c # try to figure out why it doesn't work!\n}\n\n\n2.2 YouTube Video\n\n\n2.3 Solution Code\nKarena argumen dari function mul() adalah a dan b sedangkan operasi perkalian di dalamnya menggunakan c yang belum diketahui dan tidak ada objek tersebut.\nSolusi: ganti objek c di dalam function mul() dengan b dari argumen function tersebut.\n\nmul &lt;- function(a, b) {\n a * b \n}\n\n\n2.4 Test\n\nlibrary(testthat)\n\ntest_that(\"test for associativity of multiplication\", {\n a &lt;- runif(1, 0, 10000)\n b &lt;- runif(1, 0, 10000)\n c &lt;- runif(1, 0, 10000)\n expect_equal(mul(a, b), a * b)\n expect_equal(mul(mul(a, b), c), a * b * c)\n expect_equal(mul(a, mul(b, c)), a * b * c)\n})\n\n## Test passed 🥇\n\n\n\nSupported by\n\n\nStarCore Analytics",
29
+ "crumbs": [
30
+ "2025",
31
+ "<span class='chapter-number'>2</span>  <span class='chapter-title'>Multiply</span>"
32
+ ]
33
+ },
34
+ {
35
+ "objectID": "cw0003countsheep.html",
36
+ "href": "cw0003countsheep.html",
37
+ "title": "\n3  If you can’t sleep, just count sheep!!\n",
38
+ "section": "",
39
+ "text": "8Kyu Tantangan #3/366 - 03 Feb 2025\nhttps://www.codewars.com/kata/5b077ebdaf15be5c7f000077\n\n3.1 Instruction\n\nGiven a non-negative integer, 3 for example, return a string with a murmur: \"1 sheep…2 sheep…3 sheep…\". Input will always be valid, i.e. no negative integers.\n\n\n3.2 YouTube Video\n\n\n3.3 Solution Code\nSolusi bar-bar\n\ncountSheep &lt;- function(num){\n if(num == 0){\n return(\"\")\n } else {\n result &lt;- \"\"\n for(i in 1:num){\n result &lt;- paste(result, i, \" sheep...\", sep = \"\")\n }\n return(result)\n }\n}\n\nSolusi simple\n\ncountSheep &lt;- function(num){\n ifelse(num == 0, \"\", paste(1:num, \"sheep...\", collapse = \"\"))\n}\n\n\n3.4 Test\n\nlibrary(testthat)\n\ntest_that(\"Fixed tests\", {\n expect_equal(countSheep(0), \"\")\n expect_equal(countSheep(1), \"1 sheep...\")\n expect_equal(countSheep(2), \"1 sheep...2 sheep...\")\n expect_equal(countSheep(3), \"1 sheep...2 sheep...3 sheep...\")\n})\n\n## Test passed 🥳\n\n\n\nSupported by\n\n\nStarCore Analytics",
40
+ "crumbs": [
41
+ "2025",
42
+ "<span class='chapter-number'>3</span>  <span class='chapter-title'>Count Sheep</span>"
43
+ ]
44
+ },
45
+ {
46
+ "objectID": "cw0004reducegrow.html",
47
+ "href": "cw0004reducegrow.html",
48
+ "title": "\n4  Beginner - Reduce but Grow!\n",
49
+ "section": "",
50
+ "text": "8Kyu Tantangan #4/366 - 04 Feb 2025\nhttps://www.codewars.com/kata/57f780909f7e8e3183000078\n\n4.1 Instruction\n\nGiven a non-empty array of integers, return the result of multiplying the values together in order.\n\nExample:[1, 2, 3, 4] =&gt; 1 * 2 * 3 * 4 = 24\n\n4.2 YouTube Video\n\n\n4.3 Solution Code\nSolusi bar-bar\n\ngrow &lt;- function(arr) {\n result &lt;- 1\n for(i in arr){\n result &lt;- result * i\n }\n return(result)\n}\n\nSolusi simple\n\n# grow &lt;- function(arr) prod(arr)\ngrow &lt;- prod\n\nFunction prod() adalah function untuk mengalikan nilai dari satu vector numeric, cara kerjanya sama persis dengan yang diinginkan. Oleh karena itu cukup meng-copy function prod() sebagai grow().\n\n4.4 Test\n\nlibrary(testthat)\ntest_that(\"basic tests\", {\n expect_equal(grow(c(1, 2, 3)), 6)\n expect_equal(grow(c(4, 1, 1, 1, 4)), 16)\n expect_equal(grow(c(2, 2, 2, 2, 2, 2)), 64)\n})\n\n## Test passed 🎉\n\n\n\nSupported by\n\n\nStarCore Analytics",
51
+ "crumbs": [
52
+ "2025",
53
+ "<span class='chapter-number'>4</span>  <span class='chapter-title'>Beginner - Reduce but Grow!</span>"
54
+ ]
55
+ },
56
+ {
57
+ "objectID": "cw0005makenegative.html",
58
+ "href": "cw0005makenegative.html",
59
+ "title": "\n5  Return Negative\n",
60
+ "section": "",
61
+ "text": "8Kyu Tantangan #5/366 - 05 Feb 2025\nhttps://www.codewars.com/kata/55685cd7ad70877c23000102\n\n5.1 Instruction\n\nIn this simple assignment you are given a number and have to make it negative. But maybe the number is already negative?\n\nExamples\n\nmake_negative(1); # return -1 \nmake_negative(-5); # return -5\nmake_negative(0); # return 0\n\nNotes\n\nThe number can be negative already, in which case no change is required.\n\nZero (0) is not checked for any specific sign. Negative zeros make no mathematical sense.\n\n\n5.2 YouTube Video\n\n\n5.3 Solution Code\nSolusi bar-bar\n\nmake_negative &lt;- function(num){\n ifelse(num &lt;= 0, num, -1*num)\n}\n\nSolusi simple\n\nmake_negative &lt;- function(num)-abs(num)\n\n\n5.4 Test\n\nlibrary(testthat)\n\ntest_that('Basic tests', {\n expect_equal(make_negative(42), -42)\n expect_equal(make_negative(-9), -9)\n expect_equal(make_negative(0), 0)\n expect_equal(make_negative(1), -1)\n expect_equal(make_negative(-1), -1)\n})\n\n## Test passed 🎉\n\n\n\nSupported by\n\n\nStarCore Analytics",
62
+ "crumbs": [
63
+ "2025",
64
+ "<span class='chapter-number'>5</span>  <span class='chapter-title'>Return Negative</span>"
65
+ ]
66
+ }
67
+ ]
sitemap.xml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3
+ <url>
4
+ <loc>https://huggingface.co/spaces/aephidayatuloh/codewarschallenge/index.html</loc>
5
+ <lastmod>2025-01-31T18:27:45.364Z</lastmod>
6
+ </url>
7
+ <url>
8
+ <loc>https://huggingface.co/spaces/aephidayatuloh/codewarschallenge/cw0001evenodd.html</loc>
9
+ <lastmod>2025-01-31T17:50:24.998Z</lastmod>
10
+ </url>
11
+ <url>
12
+ <loc>https://huggingface.co/spaces/aephidayatuloh/codewarschallenge/cw0002multiply.html</loc>
13
+ <lastmod>2025-01-31T18:04:40.840Z</lastmod>
14
+ </url>
15
+ <url>
16
+ <loc>https://huggingface.co/spaces/aephidayatuloh/codewarschallenge/cw0003countsheep.html</loc>
17
+ <lastmod>2025-01-31T18:11:36.320Z</lastmod>
18
+ </url>
19
+ <url>
20
+ <loc>https://huggingface.co/spaces/aephidayatuloh/codewarschallenge/cw0004reducegrow.html</loc>
21
+ <lastmod>2025-01-31T18:19:21.171Z</lastmod>
22
+ </url>
23
+ <url>
24
+ <loc>https://huggingface.co/spaces/aephidayatuloh/codewarschallenge/cw0005makenegative.html</loc>
25
+ <lastmod>2025-01-31T18:27:23.719Z</lastmod>
26
+ </url>
27
+ </urlset>
style.css CHANGED
@@ -1,28 +1,63 @@
1
- body {
2
- padding: 2rem;
3
- font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
4
- }
5
-
6
- h1 {
7
- font-size: 16px;
8
- margin-top: 0;
9
- }
10
-
11
- p {
12
- color: rgb(107, 114, 128);
13
- font-size: 15px;
14
- margin-bottom: 10px;
15
- margin-top: 5px;
16
- }
17
-
18
- .card {
19
- max-width: 620px;
20
- margin: 0 auto;
21
- padding: 16px;
22
- border: 1px solid lightgray;
23
- border-radius: 16px;
24
- }
25
-
26
- .card p:last-child {
27
- margin-bottom: 0;
28
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ body {
3
+ padding: 2rem;
4
+ font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
5
+ }
6
+
7
+ h1, .h1, .title {
8
+ font-size: 2rem;
9
+ margin-top: 0;
10
+ }
11
+
12
+ p {
13
+ color: rgb(72, 74, 80);
14
+ font-size: 15px;
15
+ margin-bottom: 10px;
16
+ margin-top: 5px;
17
+ }
18
+
19
+ .card {
20
+ max-width: 620px;
21
+ margin: 0 auto;
22
+ padding: 16px;
23
+ border: 1px solid lightgray;
24
+ border-radius: 16px;
25
+ }
26
+
27
+ .card p:last-child {
28
+ margin-bottom: 0;
29
+ }
30
+
31
+ .logo-icon {
32
+ display: flex;
33
+ justify-content: space-between;
34
+ }
35
+
36
+ .logo-icon img {
37
+ margin: 0.5rem;
38
+ width: auto; /* Sesuaikan lebar gambar agar pas dalam satu baris */
39
+ height: 8rem; /* Menjaga aspek rasio gambar */
40
+ }
41
+
42
+ .quarto-badge {
43
+ vertical-align: text-bottom;
44
+ font-size: .65em;
45
+ }
46
+
47
+ .rounded-pill {
48
+ border-radius: 50rem !important;
49
+ }
50
+
51
+ .badge {
52
+ display: inline-block;
53
+ margin-right: 0.5em;
54
+ font-size: 0.75em;
55
+ font-weight: 700;
56
+ line-height: 1;
57
+ color: rgb(255, 255, 255);
58
+ background-color: rgb(122, 122, 122);
59
+ text-align: center;
60
+ vertical-align: baseline;
61
+ padding: 0.35em 0.65em;
62
+ white-space: nowrap;
63
+ }