aepstar commited on
Commit
ae35037
·
1 Parent(s): 60fc59c
_quarto.yml CHANGED
@@ -21,6 +21,10 @@ book:
21
  - cw006positive_sum.qmd
22
  - cw007reversedstrings.qmd
23
  - cw008bool_to_word.qmd
 
 
 
 
24
 
25
 
26
  bibliography: references.bib
 
21
  - cw006positive_sum.qmd
22
  - cw007reversedstrings.qmd
23
  - cw008bool_to_word.qmd
24
+ - cw009number_to_string.qmd
25
+ - cw010opposite.qmd
26
+ - cw011removeChar.qmd
27
+ - cw012square_sum.qmd
28
 
29
 
30
  bibliography: references.bib
cw001evenodd.html CHANGED
@@ -197,6 +197,18 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
200
  </li>
201
  </ul>
202
  </div>
@@ -273,31 +285,31 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
273
  <span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">even_or_odd</span>(<span class="dv">1</span>), <span class="st">"Odd"</span>)</span>
274
  <span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
275
  <div class="cell-output cell-output-stdout">
276
- <pre><code>Test passed 🥳</code></pre>
277
  </div>
278
  <div class="sourceCode cell-code" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">'even_or_odd(2) returns "Even"'</span>, {</span>
279
  <span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">even_or_odd</span>(<span class="dv">2</span>), <span class="st">"Even"</span>)</span>
280
  <span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
281
  <div class="cell-output cell-output-stdout">
282
- <pre><code>Test passed 🥳</code></pre>
283
  </div>
284
  <div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">'even_or_odd(0) returns "Even"'</span>, {</span>
285
  <span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">even_or_odd</span>(<span class="dv">0</span>), <span class="st">"Even"</span>)</span>
286
  <span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
287
  <div class="cell-output cell-output-stdout">
288
- <pre><code>Test passed 🥇</code></pre>
289
  </div>
290
  <div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">'even_or_odd(-1) returns "Odd"'</span>, {</span>
291
  <span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">even_or_odd</span>(<span class="sc">-</span><span class="dv">1</span>), <span class="st">"Odd"</span>)</span>
292
  <span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
293
  <div class="cell-output cell-output-stdout">
294
- <pre><code>Test passed 😸</code></pre>
295
  </div>
296
  <div class="sourceCode cell-code" id="cb12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">'even_or_odd(-2) returns "Even"'</span>, {</span>
297
  <span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">even_or_odd</span>(<span class="sc">-</span><span class="dv">2</span>), <span class="st">"Even"</span>)</span>
298
  <span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
299
  <div class="cell-output cell-output-stdout">
300
- <pre><code>Test passed 🥳</code></pre>
301
  </div>
302
  </div>
303
  </section>
 
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
200
+ </li>
201
+ <li class="sidebar-item">
202
+ <div class="sidebar-item-container">
203
+ <a href="./cw009number_to_string.html" class="sidebar-item-text sidebar-link">
204
+ <span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span></a>
205
+ </div>
206
+ </li>
207
+ <li class="sidebar-item">
208
+ <div class="sidebar-item-container">
209
+ <a href="./cw010opposite.html" class="sidebar-item-text sidebar-link">
210
+ <span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span></a>
211
+ </div>
212
  </li>
213
  </ul>
214
  </div>
 
285
  <span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">even_or_odd</span>(<span class="dv">1</span>), <span class="st">"Odd"</span>)</span>
286
  <span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
287
  <div class="cell-output cell-output-stdout">
288
+ <pre><code>Test passed 😀</code></pre>
289
  </div>
290
  <div class="sourceCode cell-code" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">'even_or_odd(2) returns "Even"'</span>, {</span>
291
  <span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">even_or_odd</span>(<span class="dv">2</span>), <span class="st">"Even"</span>)</span>
292
  <span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
293
  <div class="cell-output cell-output-stdout">
294
+ <pre><code>Test passed 🎊</code></pre>
295
  </div>
296
  <div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">'even_or_odd(0) returns "Even"'</span>, {</span>
297
  <span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">even_or_odd</span>(<span class="dv">0</span>), <span class="st">"Even"</span>)</span>
298
  <span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
299
  <div class="cell-output cell-output-stdout">
300
+ <pre><code>Test passed 🎉</code></pre>
301
  </div>
302
  <div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">'even_or_odd(-1) returns "Odd"'</span>, {</span>
303
  <span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">even_or_odd</span>(<span class="sc">-</span><span class="dv">1</span>), <span class="st">"Odd"</span>)</span>
304
  <span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
305
  <div class="cell-output cell-output-stdout">
306
+ <pre><code>Test passed 🌈</code></pre>
307
  </div>
308
  <div class="sourceCode cell-code" id="cb12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">'even_or_odd(-2) returns "Even"'</span>, {</span>
309
  <span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">even_or_odd</span>(<span class="sc">-</span><span class="dv">2</span>), <span class="st">"Even"</span>)</span>
310
  <span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
311
  <div class="cell-output cell-output-stdout">
312
+ <pre><code>Test passed 🎉</code></pre>
313
  </div>
314
  </div>
315
  </section>
cw002multiply.html CHANGED
@@ -197,6 +197,18 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
200
  </li>
201
  </ul>
202
  </div>
@@ -278,7 +290,7 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
278
  <span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">mul</span>(a, <span class="fu">mul</span>(b, c)), a <span class="sc">*</span> b <span class="sc">*</span> c)</span>
279
  <span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
280
  <div class="cell-output cell-output-stdout">
281
- <pre><code>Test passed 😸</code></pre>
282
  </div>
283
  </div>
284
  </section>
 
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
200
+ </li>
201
+ <li class="sidebar-item">
202
+ <div class="sidebar-item-container">
203
+ <a href="./cw009number_to_string.html" class="sidebar-item-text sidebar-link">
204
+ <span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span></a>
205
+ </div>
206
+ </li>
207
+ <li class="sidebar-item">
208
+ <div class="sidebar-item-container">
209
+ <a href="./cw010opposite.html" class="sidebar-item-text sidebar-link">
210
+ <span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span></a>
211
+ </div>
212
  </li>
213
  </ul>
214
  </div>
 
290
  <span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">mul</span>(a, <span class="fu">mul</span>(b, c)), a <span class="sc">*</span> b <span class="sc">*</span> c)</span>
291
  <span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
292
  <div class="cell-output cell-output-stdout">
293
+ <pre><code>Test passed 🥇</code></pre>
294
  </div>
295
  </div>
296
  </section>
cw003countsheep.html CHANGED
@@ -197,6 +197,18 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
200
  </li>
201
  </ul>
202
  </div>
@@ -281,7 +293,7 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
281
  <span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">countSheep</span>(<span class="dv">3</span>), <span class="st">"1 sheep...2 sheep...3 sheep..."</span>)</span>
282
  <span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
283
  <div class="cell-output cell-output-stdout">
284
- <pre><code>Test passed 🥇</code></pre>
285
  </div>
286
  </div>
287
  </section>
 
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
200
+ </li>
201
+ <li class="sidebar-item">
202
+ <div class="sidebar-item-container">
203
+ <a href="./cw009number_to_string.html" class="sidebar-item-text sidebar-link">
204
+ <span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span></a>
205
+ </div>
206
+ </li>
207
+ <li class="sidebar-item">
208
+ <div class="sidebar-item-container">
209
+ <a href="./cw010opposite.html" class="sidebar-item-text sidebar-link">
210
+ <span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span></a>
211
+ </div>
212
  </li>
213
  </ul>
214
  </div>
 
293
  <span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">countSheep</span>(<span class="dv">3</span>), <span class="st">"1 sheep...2 sheep...3 sheep..."</span>)</span>
294
  <span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
295
  <div class="cell-output cell-output-stdout">
296
+ <pre><code>Test passed 🎊</code></pre>
297
  </div>
298
  </div>
299
  </section>
cw004reducegrow.html CHANGED
@@ -197,6 +197,18 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
200
  </li>
201
  </ul>
202
  </div>
@@ -275,7 +287,7 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
275
  <span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">grow</span>(<span class="fu">c</span>(<span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">2</span>)), <span class="dv">64</span>)</span>
276
  <span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
277
  <div class="cell-output cell-output-stdout">
278
- <pre><code>Test passed 😸</code></pre>
279
  </div>
280
  </div>
281
  </section>
 
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
200
+ </li>
201
+ <li class="sidebar-item">
202
+ <div class="sidebar-item-container">
203
+ <a href="./cw009number_to_string.html" class="sidebar-item-text sidebar-link">
204
+ <span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span></a>
205
+ </div>
206
+ </li>
207
+ <li class="sidebar-item">
208
+ <div class="sidebar-item-container">
209
+ <a href="./cw010opposite.html" class="sidebar-item-text sidebar-link">
210
+ <span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span></a>
211
+ </div>
212
  </li>
213
  </ul>
214
  </div>
 
287
  <span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">grow</span>(<span class="fu">c</span>(<span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">2</span>)), <span class="dv">64</span>)</span>
288
  <span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
289
  <div class="cell-output cell-output-stdout">
290
+ <pre><code>Test passed 🥳</code></pre>
291
  </div>
292
  </div>
293
  </section>
cw005make_negative.html CHANGED
@@ -197,6 +197,18 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
200
  </li>
201
  </ul>
202
  </div>
@@ -278,7 +290,7 @@ The number can be negative already, in which case no change is required. Zero (0
278
  <span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">make_negative</span>(<span class="sc">-</span><span class="dv">1</span>), <span class="sc">-</span><span class="dv">1</span>)</span>
279
  <span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
280
  <div class="cell-output cell-output-stdout">
281
- <pre><code>Test passed 😀</code></pre>
282
  </div>
283
  </div>
284
  </section>
 
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
200
+ </li>
201
+ <li class="sidebar-item">
202
+ <div class="sidebar-item-container">
203
+ <a href="./cw009number_to_string.html" class="sidebar-item-text sidebar-link">
204
+ <span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span></a>
205
+ </div>
206
+ </li>
207
+ <li class="sidebar-item">
208
+ <div class="sidebar-item-container">
209
+ <a href="./cw010opposite.html" class="sidebar-item-text sidebar-link">
210
+ <span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span></a>
211
+ </div>
212
  </li>
213
  </ul>
214
  </div>
 
290
  <span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">make_negative</span>(<span class="sc">-</span><span class="dv">1</span>), <span class="sc">-</span><span class="dv">1</span>)</span>
291
  <span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
292
  <div class="cell-output cell-output-stdout">
293
+ <pre><code>Test passed 😸</code></pre>
294
  </div>
295
  </div>
296
  </section>
cw006positive_sum.html CHANGED
@@ -197,6 +197,18 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
200
  </li>
201
  </ul>
202
  </div>
@@ -288,7 +300,7 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
288
  <span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">positive_sum</span>(<span class="fu">c</span>(<span class="sc">-</span><span class="dv">1</span>,<span class="sc">-</span><span class="dv">2</span>,<span class="sc">-</span><span class="dv">3</span>,<span class="sc">-</span><span class="dv">4</span>,<span class="sc">-</span><span class="dv">5</span>)),<span class="dv">0</span>)</span>
289
  <span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
290
  <div class="cell-output cell-output-stdout">
291
- <pre><code>Test passed 🎉</code></pre>
292
  </div>
293
  </div>
294
  </section>
 
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
200
+ </li>
201
+ <li class="sidebar-item">
202
+ <div class="sidebar-item-container">
203
+ <a href="./cw009number_to_string.html" class="sidebar-item-text sidebar-link">
204
+ <span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span></a>
205
+ </div>
206
+ </li>
207
+ <li class="sidebar-item">
208
+ <div class="sidebar-item-container">
209
+ <a href="./cw010opposite.html" class="sidebar-item-text sidebar-link">
210
+ <span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span></a>
211
+ </div>
212
  </li>
213
  </ul>
214
  </div>
 
300
  <span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">positive_sum</span>(<span class="fu">c</span>(<span class="sc">-</span><span class="dv">1</span>,<span class="sc">-</span><span class="dv">2</span>,<span class="sc">-</span><span class="dv">3</span>,<span class="sc">-</span><span class="dv">4</span>,<span class="sc">-</span><span class="dv">5</span>)),<span class="dv">0</span>)</span>
301
  <span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
302
  <div class="cell-output cell-output-stdout">
303
+ <pre><code>Test passed 🥳</code></pre>
304
  </div>
305
  </div>
306
  </section>
cw007reversedstrings.html CHANGED
@@ -197,6 +197,18 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
200
  </li>
201
  </ul>
202
  </div>
@@ -276,7 +288,7 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
276
  <span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">solution</span>(<span class="st">'h'</span>), <span class="st">'h'</span>)</span>
277
  <span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
278
  <div class="cell-output cell-output-stdout">
279
- <pre><code>Test passed 🥇</code></pre>
280
  </div>
281
  </div>
282
  </section>
 
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
200
+ </li>
201
+ <li class="sidebar-item">
202
+ <div class="sidebar-item-container">
203
+ <a href="./cw009number_to_string.html" class="sidebar-item-text sidebar-link">
204
+ <span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span></a>
205
+ </div>
206
+ </li>
207
+ <li class="sidebar-item">
208
+ <div class="sidebar-item-container">
209
+ <a href="./cw010opposite.html" class="sidebar-item-text sidebar-link">
210
+ <span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span></a>
211
+ </div>
212
  </li>
213
  </ul>
214
  </div>
 
288
  <span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">solution</span>(<span class="st">'h'</span>), <span class="st">'h'</span>)</span>
289
  <span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
290
  <div class="cell-output cell-output-stdout">
291
+ <pre><code>Test passed 😸</code></pre>
292
  </div>
293
  </div>
294
  </section>
cw008bool_to_word.html CHANGED
@@ -64,6 +64,7 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
64
  <script src="site_libs/quarto-search/fuse.min.js"></script>
65
  <script src="site_libs/quarto-search/quarto-search.js"></script>
66
  <meta name="quarto:offset" content="./">
 
67
  <link href="./cw007reversedstrings.html" rel="prev">
68
  <link href="./logo.png" rel="icon" type="image/png">
69
  <script src="site_libs/quarto-html/quarto.js"></script>
@@ -196,6 +197,18 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
196
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link active">
197
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
198
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
199
  </li>
200
  </ul>
201
  </div>
@@ -264,7 +277,7 @@ pre > code.sourceCode > span > a:first-child::before { text-decoration: underlin
264
  <span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">bool_to_word</span>(<span class="cn">FALSE</span>), <span class="st">'No'</span>)</span>
265
  <span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
266
  <div class="cell-output cell-output-stdout">
267
- <pre><code>Test passed 🎊</code></pre>
268
  </div>
269
  </div>
270
  </section>
@@ -521,6 +534,9 @@ window.document.addEventListener("DOMContentLoaded", function (event) {
521
  </a>
522
  </div>
523
  <div class="nav-page nav-page-next">
 
 
 
524
  </div>
525
  </nav>
526
  </div> <!-- /content -->
 
64
  <script src="site_libs/quarto-search/fuse.min.js"></script>
65
  <script src="site_libs/quarto-search/quarto-search.js"></script>
66
  <meta name="quarto:offset" content="./">
67
+ <link href="./cw009number_to_string.html" rel="next">
68
  <link href="./cw007reversedstrings.html" rel="prev">
69
  <link href="./logo.png" rel="icon" type="image/png">
70
  <script src="site_libs/quarto-html/quarto.js"></script>
 
197
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link active">
198
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
  </div>
200
+ </li>
201
+ <li class="sidebar-item">
202
+ <div class="sidebar-item-container">
203
+ <a href="./cw009number_to_string.html" class="sidebar-item-text sidebar-link">
204
+ <span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span></a>
205
+ </div>
206
+ </li>
207
+ <li class="sidebar-item">
208
+ <div class="sidebar-item-container">
209
+ <a href="./cw010opposite.html" class="sidebar-item-text sidebar-link">
210
+ <span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span></a>
211
+ </div>
212
  </li>
213
  </ul>
214
  </div>
 
277
  <span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">bool_to_word</span>(<span class="cn">FALSE</span>), <span class="st">'No'</span>)</span>
278
  <span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
279
  <div class="cell-output cell-output-stdout">
280
+ <pre><code>Test passed 🥳</code></pre>
281
  </div>
282
  </div>
283
  </section>
 
534
  </a>
535
  </div>
536
  <div class="nav-page nav-page-next">
537
+ <a href="./cw009number_to_string.html" class="pagination-link">
538
+ <span class="nav-page-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span> <i class="bi bi-arrow-right-short"></i>
539
+ </a>
540
  </div>
541
  </nav>
542
  </div> <!-- /content -->
cw009number_to_string.html ADDED
@@ -0,0 +1,555 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.3.433">
6
+
7
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
8
+
9
+
10
+ <title>Codewars Challenge 2024 Menggunakan R dan RStudio - 9&nbsp; Convert a Number to a String!</title>
11
+ <style>
12
+ code{white-space: pre-wrap;}
13
+ span.smallcaps{font-variant: small-caps;}
14
+ div.columns{display: flex; gap: min(4vw, 1.5em);}
15
+ div.column{flex: auto; overflow-x: auto;}
16
+ div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
17
+ ul.task-list{list-style: none;}
18
+ ul.task-list li input[type="checkbox"] {
19
+ width: 0.8em;
20
+ margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
21
+ vertical-align: middle;
22
+ }
23
+ /* CSS for syntax highlighting */
24
+ pre > code.sourceCode { white-space: pre; position: relative; }
25
+ pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
26
+ pre > code.sourceCode > span:empty { height: 1.2em; }
27
+ .sourceCode { overflow: visible; }
28
+ code.sourceCode > span { color: inherit; text-decoration: inherit; }
29
+ div.sourceCode { margin: 1em 0; }
30
+ pre.sourceCode { margin: 0; }
31
+ @media screen {
32
+ div.sourceCode { overflow: auto; }
33
+ }
34
+ @media print {
35
+ pre > code.sourceCode { white-space: pre-wrap; }
36
+ pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
37
+ }
38
+ pre.numberSource code
39
+ { counter-reset: source-line 0; }
40
+ pre.numberSource code > span
41
+ { position: relative; left: -4em; counter-increment: source-line; }
42
+ pre.numberSource code > span > a:first-child::before
43
+ { content: counter(source-line);
44
+ position: relative; left: -1em; text-align: right; vertical-align: baseline;
45
+ border: none; display: inline-block;
46
+ -webkit-touch-callout: none; -webkit-user-select: none;
47
+ -khtml-user-select: none; -moz-user-select: none;
48
+ -ms-user-select: none; user-select: none;
49
+ padding: 0 4px; width: 4em;
50
+ }
51
+ pre.numberSource { margin-left: 3em; padding-left: 4px; }
52
+ div.sourceCode
53
+ { }
54
+ @media screen {
55
+ pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
56
+ }
57
+ </style>
58
+
59
+
60
+ <script src="site_libs/quarto-nav/quarto-nav.js"></script>
61
+ <script src="site_libs/quarto-nav/headroom.min.js"></script>
62
+ <script src="site_libs/clipboard/clipboard.min.js"></script>
63
+ <script src="site_libs/quarto-search/autocomplete.umd.js"></script>
64
+ <script src="site_libs/quarto-search/fuse.min.js"></script>
65
+ <script src="site_libs/quarto-search/quarto-search.js"></script>
66
+ <meta name="quarto:offset" content="./">
67
+ <link href="./cw010opposite.html" rel="next">
68
+ <link href="./cw008bool_to_word.html" rel="prev">
69
+ <link href="./logo.png" rel="icon" type="image/png">
70
+ <script src="site_libs/quarto-html/quarto.js"></script>
71
+ <script src="site_libs/quarto-html/popper.min.js"></script>
72
+ <script src="site_libs/quarto-html/tippy.umd.min.js"></script>
73
+ <script src="site_libs/quarto-html/anchor.min.js"></script>
74
+ <link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
75
+ <link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
76
+ <script src="site_libs/bootstrap/bootstrap.min.js"></script>
77
+ <link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
78
+ <link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
79
+ <link href="site_libs/quarto-contrib/badge/badge.css" rel="stylesheet">
80
+ <script id="quarto-search-options" type="application/json">{
81
+ "location": "sidebar",
82
+ "copy-button": false,
83
+ "collapse-after": 3,
84
+ "panel-placement": "start",
85
+ "type": "textbox",
86
+ "limit": 20,
87
+ "language": {
88
+ "search-no-results-text": "No results",
89
+ "search-matching-documents-text": "matching documents",
90
+ "search-copy-link-title": "Copy link to search",
91
+ "search-hide-matches-text": "Hide additional matches",
92
+ "search-more-match-text": "more match in this document",
93
+ "search-more-matches-text": "more matches in this document",
94
+ "search-clear-button-title": "Clear",
95
+ "search-detached-cancel-button-title": "Cancel",
96
+ "search-submit-button-title": "Submit",
97
+ "search-label": "Search"
98
+ }
99
+ }</script>
100
+
101
+
102
+ <meta name="twitter:title" content="Codewars Challenge 2024 Menggunakan R dan RStudio - 9&nbsp; Convert a Number to a String!">
103
+ <meta name="twitter:description" content="">
104
+ <meta name="twitter:image" content="https://huggingface.co/spaces/aephidayatuloh/codewars2024/new_starcore_logo.png">
105
+ <meta name="twitter:image-height" content="434">
106
+ <meta name="twitter:image-width" content="1946">
107
+ <meta name="twitter:card" content="summary_large_image">
108
+ </head>
109
+
110
+ <body class="nav-sidebar floating">
111
+
112
+ <div id="quarto-search-results"></div>
113
+ <header id="quarto-header" class="headroom fixed-top">
114
+ <nav class="quarto-secondary-nav">
115
+ <div class="container-fluid d-flex">
116
+ <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
117
+ <i class="bi bi-layout-text-sidebar-reverse"></i>
118
+ </button>
119
+ <nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./cw009number_to_string.html"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></a></li></ol></nav>
120
+ <a class="flex-grow-1" role="button" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
121
+ </a>
122
+ <button type="button" class="btn quarto-search-button" aria-label="" onclick="window.quartoOpenSearch();">
123
+ <i class="bi bi-search"></i>
124
+ </button>
125
+ </div>
126
+ </nav>
127
+ </header>
128
+ <!-- content -->
129
+ <div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
130
+ <!-- sidebar -->
131
+ <nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal sidebar-navigation floating overflow-auto">
132
+ <div class="pt-lg-2 mt-2 text-left sidebar-header">
133
+ <div class="sidebar-title mb-0 py-0">
134
+ <a href="./">Codewars Challenge 2024 Menggunakan R dan RStudio</a>
135
+ <div class="sidebar-tools-main">
136
+ <a href="https://huggingface.co/spaces/aephidayatuloh/codewars2024/tree/main" rel="" title="Source Code" class="quarto-navigation-tool px-1" aria-label="Source Code"><i class="bi bi-git"></i></a>
137
+ </div>
138
+ </div>
139
+ </div>
140
+ <div class="mt-2 flex-shrink-0 align-items-center">
141
+ <div class="sidebar-search">
142
+ <div id="quarto-search" class="" title="Search"></div>
143
+ </div>
144
+ </div>
145
+ <div class="sidebar-menu-container">
146
+ <ul class="list-unstyled mt-1">
147
+ <li class="sidebar-item">
148
+ <div class="sidebar-item-container">
149
+ <a href="./index.html" class="sidebar-item-text sidebar-link">
150
+ <span class="menu-text">Pengantar</span></a>
151
+ </div>
152
+ </li>
153
+ <li class="sidebar-item">
154
+ <div class="sidebar-item-container">
155
+ <a href="./cw001evenodd.html" class="sidebar-item-text sidebar-link">
156
+ <span class="menu-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span></span></a>
157
+ </div>
158
+ </li>
159
+ <li class="sidebar-item">
160
+ <div class="sidebar-item-container">
161
+ <a href="./cw002multiply.html" class="sidebar-item-text sidebar-link">
162
+ <span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span></span></a>
163
+ </div>
164
+ </li>
165
+ <li class="sidebar-item">
166
+ <div class="sidebar-item-container">
167
+ <a href="./cw003countsheep.html" class="sidebar-item-text sidebar-link">
168
+ <span class="menu-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">If you can’t sleep, just count sheep!!</span></span></a>
169
+ </div>
170
+ </li>
171
+ <li class="sidebar-item">
172
+ <div class="sidebar-item-container">
173
+ <a href="./cw004reducegrow.html" class="sidebar-item-text sidebar-link">
174
+ <span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow</span></span></a>
175
+ </div>
176
+ </li>
177
+ <li class="sidebar-item">
178
+ <div class="sidebar-item-container">
179
+ <a href="./cw005make_negative.html" class="sidebar-item-text sidebar-link">
180
+ <span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Return Negative</span></span></a>
181
+ </div>
182
+ </li>
183
+ <li class="sidebar-item">
184
+ <div class="sidebar-item-container">
185
+ <a href="./cw006positive_sum.html" class="sidebar-item-text sidebar-link">
186
+ <span class="menu-text"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Sum of positive</span></span></a>
187
+ </div>
188
+ </li>
189
+ <li class="sidebar-item">
190
+ <div class="sidebar-item-container">
191
+ <a href="./cw007reversedstrings.html" class="sidebar-item-text sidebar-link">
192
+ <span class="menu-text"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Reversed Strings</span></span></a>
193
+ </div>
194
+ </li>
195
+ <li class="sidebar-item">
196
+ <div class="sidebar-item-container">
197
+ <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
+ <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
+ </div>
200
+ </li>
201
+ <li class="sidebar-item">
202
+ <div class="sidebar-item-container">
203
+ <a href="./cw009number_to_string.html" class="sidebar-item-text sidebar-link active">
204
+ <span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span></a>
205
+ </div>
206
+ </li>
207
+ <li class="sidebar-item">
208
+ <div class="sidebar-item-container">
209
+ <a href="./cw010opposite.html" class="sidebar-item-text sidebar-link">
210
+ <span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span></a>
211
+ </div>
212
+ </li>
213
+ </ul>
214
+ </div>
215
+ </nav>
216
+ <div id="quarto-sidebar-glass" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass"></div>
217
+ <!-- margin-sidebar -->
218
+ <div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
219
+ <nav id="TOC" role="doc-toc" class="toc-active">
220
+ <h2 id="toc-title">Table of contents</h2>
221
+
222
+ <ul>
223
+ <li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">9.1</span> Instruction</a></li>
224
+ <li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">9.2</span> YouTube Video</a></li>
225
+ <li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">9.3</span> Solution Code</a></li>
226
+ <li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">9.4</span> Test</a></li>
227
+ <li><a href="#supported-by" id="toc-supported-by" class="nav-link" data-scroll-target="#supported-by"><span class="header-section-number">9.5</span> Supported by</a></li>
228
+ </ul>
229
+ </nav>
230
+ </div>
231
+ <!-- main -->
232
+ <main class="content" id="quarto-document-content">
233
+
234
+ <header id="title-block-header" class="quarto-title-block default">
235
+ <div class="quarto-title">
236
+ <h1 class="title"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></h1>
237
+ </div>
238
+
239
+
240
+
241
+ <div class="quarto-title-meta">
242
+
243
+
244
+
245
+
246
+ </div>
247
+
248
+
249
+ </header>
250
+
251
+ <p><span class="badge rounded-pill quarto-badge " style="background-color: grey;">8kyu</span> Tantangan #9/366 - 23 Feb 2024</p>
252
+ <p><a href="https://www.codewars.com/kata/5265326f5fda8eb1160004c8/train/r" class="uri">https://www.codewars.com/kata/5265326f5fda8eb1160004c8/train/r</a></p>
253
+ <section id="instruction" class="level2" data-number="9.1">
254
+ <h2 data-number="9.1" class="anchored" data-anchor-id="instruction"><span class="header-section-number">9.1</span> Instruction</h2>
255
+ <p>We need a function that can transform a number (integer) into a string.</p>
256
+ <p>What ways of achieving this do you know?</p>
257
+ <p>Examples (input –&gt; output):</p>
258
+ <pre><code>123 --&gt; "123"
259
+ 999 --&gt; "999"
260
+ -100 --&gt; "-100"</code></pre>
261
+ </section>
262
+ <section id="youtube-video" class="level2" data-number="9.2">
263
+ <h2 data-number="9.2" class="anchored" data-anchor-id="youtube-video"><span class="header-section-number">9.2</span> YouTube Video</h2>
264
+ <div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/L8aczEhqymk?si=DSx84acpNvbkucrK" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
265
+ </section>
266
+ <section id="solution-code" class="level2" data-number="9.3">
267
+ <h2 data-number="9.3" class="anchored" data-anchor-id="solution-code"><span class="header-section-number">9.3</span> Solution Code</h2>
268
+ <div class="cell">
269
+ <div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>number_to_string <span class="ot">&lt;-</span> <span class="cf">function</span>(n) {</span>
270
+ <span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">as.character</span>(n)</span>
271
+ <span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
272
+ </div>
273
+ <div class="cell">
274
+ <div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>number_to_string <span class="ot">&lt;-</span> as.character</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
275
+ </div>
276
+ </section>
277
+ <section id="test" class="level2" data-number="9.4">
278
+ <h2 data-number="9.4" class="anchored" data-anchor-id="test"><span class="header-section-number">9.4</span> Test</h2>
279
+ <div class="cell">
280
+ <div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(testthat)</span>
281
+ <span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
282
+ <span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">"fixed tests"</span>, {</span>
283
+ <span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">number_to_string</span>(<span class="dv">67</span>), <span class="st">'67'</span>)</span>
284
+ <span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">number_to_string</span>(<span class="dv">79585</span>), <span class="st">'79585'</span>)</span>
285
+ <span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">number_to_string</span>(<span class="dv">3</span>), <span class="st">'3'</span>)</span>
286
+ <span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">number_to_string</span>(<span class="sc">-</span><span class="dv">1</span>), <span class="st">'-1'</span>)</span>
287
+ <span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
288
+ <div class="cell-output cell-output-stdout">
289
+ <pre><code>Test passed 🥇</code></pre>
290
+ </div>
291
+ </div>
292
+ </section>
293
+ <section id="supported-by" class="level2" data-number="9.5">
294
+ <h2 data-number="9.5" class="anchored" data-anchor-id="supported-by"><span class="header-section-number">9.5</span> Supported by</h2>
295
+ <div class="quarto-figure quarto-figure-center">
296
+ <figure class="figure">
297
+ <p><a href="https://www.starcore.co"><img src="new_starcore_logo.png" class="img-fluid figure-img"></a></p>
298
+ <figcaption class="figure-caption">StarCore Analytics</figcaption>
299
+ </figure>
300
+ </div>
301
+
302
+
303
+ </section>
304
+
305
+ </main> <!-- /main -->
306
+ <script id="quarto-html-after-body" type="application/javascript">
307
+ window.document.addEventListener("DOMContentLoaded", function (event) {
308
+ const toggleBodyColorMode = (bsSheetEl) => {
309
+ const mode = bsSheetEl.getAttribute("data-mode");
310
+ const bodyEl = window.document.querySelector("body");
311
+ if (mode === "dark") {
312
+ bodyEl.classList.add("quarto-dark");
313
+ bodyEl.classList.remove("quarto-light");
314
+ } else {
315
+ bodyEl.classList.add("quarto-light");
316
+ bodyEl.classList.remove("quarto-dark");
317
+ }
318
+ }
319
+ const toggleBodyColorPrimary = () => {
320
+ const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
321
+ if (bsSheetEl) {
322
+ toggleBodyColorMode(bsSheetEl);
323
+ }
324
+ }
325
+ toggleBodyColorPrimary();
326
+ const icon = "";
327
+ const anchorJS = new window.AnchorJS();
328
+ anchorJS.options = {
329
+ placement: 'right',
330
+ icon: icon
331
+ };
332
+ anchorJS.add('.anchored');
333
+ const isCodeAnnotation = (el) => {
334
+ for (const clz of el.classList) {
335
+ if (clz.startsWith('code-annotation-')) {
336
+ return true;
337
+ }
338
+ }
339
+ return false;
340
+ }
341
+ const clipboard = new window.ClipboardJS('.code-copy-button', {
342
+ text: function(trigger) {
343
+ const codeEl = trigger.previousElementSibling.cloneNode(true);
344
+ for (const childEl of codeEl.children) {
345
+ if (isCodeAnnotation(childEl)) {
346
+ childEl.remove();
347
+ }
348
+ }
349
+ return codeEl.innerText;
350
+ }
351
+ });
352
+ clipboard.on('success', function(e) {
353
+ // button target
354
+ const button = e.trigger;
355
+ // don't keep focus
356
+ button.blur();
357
+ // flash "checked"
358
+ button.classList.add('code-copy-button-checked');
359
+ var currentTitle = button.getAttribute("title");
360
+ button.setAttribute("title", "Copied!");
361
+ let tooltip;
362
+ if (window.bootstrap) {
363
+ button.setAttribute("data-bs-toggle", "tooltip");
364
+ button.setAttribute("data-bs-placement", "left");
365
+ button.setAttribute("data-bs-title", "Copied!");
366
+ tooltip = new bootstrap.Tooltip(button,
367
+ { trigger: "manual",
368
+ customClass: "code-copy-button-tooltip",
369
+ offset: [0, -8]});
370
+ tooltip.show();
371
+ }
372
+ setTimeout(function() {
373
+ if (tooltip) {
374
+ tooltip.hide();
375
+ button.removeAttribute("data-bs-title");
376
+ button.removeAttribute("data-bs-toggle");
377
+ button.removeAttribute("data-bs-placement");
378
+ }
379
+ button.setAttribute("title", currentTitle);
380
+ button.classList.remove('code-copy-button-checked');
381
+ }, 1000);
382
+ // clear code selection
383
+ e.clearSelection();
384
+ });
385
+ function tippyHover(el, contentFn) {
386
+ const config = {
387
+ allowHTML: true,
388
+ content: contentFn,
389
+ maxWidth: 500,
390
+ delay: 100,
391
+ arrow: false,
392
+ appendTo: function(el) {
393
+ return el.parentElement;
394
+ },
395
+ interactive: true,
396
+ interactiveBorder: 10,
397
+ theme: 'quarto',
398
+ placement: 'bottom-start'
399
+ };
400
+ window.tippy(el, config);
401
+ }
402
+ const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
403
+ for (var i=0; i<noterefs.length; i++) {
404
+ const ref = noterefs[i];
405
+ tippyHover(ref, function() {
406
+ // use id or data attribute instead here
407
+ let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
408
+ try { href = new URL(href).hash; } catch {}
409
+ const id = href.replace(/^#\/?/, "");
410
+ const note = window.document.getElementById(id);
411
+ return note.innerHTML;
412
+ });
413
+ }
414
+ let selectedAnnoteEl;
415
+ const selectorForAnnotation = ( cell, annotation) => {
416
+ let cellAttr = 'data-code-cell="' + cell + '"';
417
+ let lineAttr = 'data-code-annotation="' + annotation + '"';
418
+ const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
419
+ return selector;
420
+ }
421
+ const selectCodeLines = (annoteEl) => {
422
+ const doc = window.document;
423
+ const targetCell = annoteEl.getAttribute("data-target-cell");
424
+ const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
425
+ const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
426
+ const lines = annoteSpan.getAttribute("data-code-lines").split(",");
427
+ const lineIds = lines.map((line) => {
428
+ return targetCell + "-" + line;
429
+ })
430
+ let top = null;
431
+ let height = null;
432
+ let parent = null;
433
+ if (lineIds.length > 0) {
434
+ //compute the position of the single el (top and bottom and make a div)
435
+ const el = window.document.getElementById(lineIds[0]);
436
+ top = el.offsetTop;
437
+ height = el.offsetHeight;
438
+ parent = el.parentElement.parentElement;
439
+ if (lineIds.length > 1) {
440
+ const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
441
+ const bottom = lastEl.offsetTop + lastEl.offsetHeight;
442
+ height = bottom - top;
443
+ }
444
+ if (top !== null && height !== null && parent !== null) {
445
+ // cook up a div (if necessary) and position it
446
+ let div = window.document.getElementById("code-annotation-line-highlight");
447
+ if (div === null) {
448
+ div = window.document.createElement("div");
449
+ div.setAttribute("id", "code-annotation-line-highlight");
450
+ div.style.position = 'absolute';
451
+ parent.appendChild(div);
452
+ }
453
+ div.style.top = top - 2 + "px";
454
+ div.style.height = height + 4 + "px";
455
+ let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
456
+ if (gutterDiv === null) {
457
+ gutterDiv = window.document.createElement("div");
458
+ gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
459
+ gutterDiv.style.position = 'absolute';
460
+ const codeCell = window.document.getElementById(targetCell);
461
+ const gutter = codeCell.querySelector('.code-annotation-gutter');
462
+ gutter.appendChild(gutterDiv);
463
+ }
464
+ gutterDiv.style.top = top - 2 + "px";
465
+ gutterDiv.style.height = height + 4 + "px";
466
+ }
467
+ selectedAnnoteEl = annoteEl;
468
+ }
469
+ };
470
+ const unselectCodeLines = () => {
471
+ const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
472
+ elementsIds.forEach((elId) => {
473
+ const div = window.document.getElementById(elId);
474
+ if (div) {
475
+ div.remove();
476
+ }
477
+ });
478
+ selectedAnnoteEl = undefined;
479
+ };
480
+ // Attach click handler to the DT
481
+ const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
482
+ for (const annoteDlNode of annoteDls) {
483
+ annoteDlNode.addEventListener('click', (event) => {
484
+ const clickedEl = event.target;
485
+ if (clickedEl !== selectedAnnoteEl) {
486
+ unselectCodeLines();
487
+ const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
488
+ if (activeEl) {
489
+ activeEl.classList.remove('code-annotation-active');
490
+ }
491
+ selectCodeLines(clickedEl);
492
+ clickedEl.classList.add('code-annotation-active');
493
+ } else {
494
+ // Unselect the line
495
+ unselectCodeLines();
496
+ clickedEl.classList.remove('code-annotation-active');
497
+ }
498
+ });
499
+ }
500
+ const findCites = (el) => {
501
+ const parentEl = el.parentElement;
502
+ if (parentEl) {
503
+ const cites = parentEl.dataset.cites;
504
+ if (cites) {
505
+ return {
506
+ el,
507
+ cites: cites.split(' ')
508
+ };
509
+ } else {
510
+ return findCites(el.parentElement)
511
+ }
512
+ } else {
513
+ return undefined;
514
+ }
515
+ };
516
+ var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
517
+ for (var i=0; i<bibliorefs.length; i++) {
518
+ const ref = bibliorefs[i];
519
+ const citeInfo = findCites(ref);
520
+ if (citeInfo) {
521
+ tippyHover(citeInfo.el, function() {
522
+ var popup = window.document.createElement('div');
523
+ citeInfo.cites.forEach(function(cite) {
524
+ var citeDiv = window.document.createElement('div');
525
+ citeDiv.classList.add('hanging-indent');
526
+ citeDiv.classList.add('csl-entry');
527
+ var biblioDiv = window.document.getElementById('ref-' + cite);
528
+ if (biblioDiv) {
529
+ citeDiv.innerHTML = biblioDiv.innerHTML;
530
+ }
531
+ popup.appendChild(citeDiv);
532
+ });
533
+ return popup.innerHTML;
534
+ });
535
+ }
536
+ }
537
+ });
538
+ </script>
539
+ <nav class="page-navigation">
540
+ <div class="nav-page nav-page-previous">
541
+ <a href="./cw008bool_to_word.html" class="pagination-link">
542
+ <i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span>
543
+ </a>
544
+ </div>
545
+ <div class="nav-page nav-page-next">
546
+ <a href="./cw010opposite.html" class="pagination-link">
547
+ <span class="nav-page-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span> <i class="bi bi-arrow-right-short"></i>
548
+ </a>
549
+ </div>
550
+ </nav>
551
+ </div> <!-- /content -->
552
+
553
+
554
+
555
+ </body></html>
cw010opposite.html ADDED
@@ -0,0 +1,581 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.3.433">
6
+
7
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
8
+
9
+
10
+ <title>Codewars Challenge 2024 Menggunakan R dan RStudio - 10&nbsp; Opposite number</title>
11
+ <style>
12
+ code{white-space: pre-wrap;}
13
+ span.smallcaps{font-variant: small-caps;}
14
+ div.columns{display: flex; gap: min(4vw, 1.5em);}
15
+ div.column{flex: auto; overflow-x: auto;}
16
+ div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
17
+ ul.task-list{list-style: none;}
18
+ ul.task-list li input[type="checkbox"] {
19
+ width: 0.8em;
20
+ margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
21
+ vertical-align: middle;
22
+ }
23
+ /* CSS for syntax highlighting */
24
+ pre > code.sourceCode { white-space: pre; position: relative; }
25
+ pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
26
+ pre > code.sourceCode > span:empty { height: 1.2em; }
27
+ .sourceCode { overflow: visible; }
28
+ code.sourceCode > span { color: inherit; text-decoration: inherit; }
29
+ div.sourceCode { margin: 1em 0; }
30
+ pre.sourceCode { margin: 0; }
31
+ @media screen {
32
+ div.sourceCode { overflow: auto; }
33
+ }
34
+ @media print {
35
+ pre > code.sourceCode { white-space: pre-wrap; }
36
+ pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
37
+ }
38
+ pre.numberSource code
39
+ { counter-reset: source-line 0; }
40
+ pre.numberSource code > span
41
+ { position: relative; left: -4em; counter-increment: source-line; }
42
+ pre.numberSource code > span > a:first-child::before
43
+ { content: counter(source-line);
44
+ position: relative; left: -1em; text-align: right; vertical-align: baseline;
45
+ border: none; display: inline-block;
46
+ -webkit-touch-callout: none; -webkit-user-select: none;
47
+ -khtml-user-select: none; -moz-user-select: none;
48
+ -ms-user-select: none; user-select: none;
49
+ padding: 0 4px; width: 4em;
50
+ }
51
+ pre.numberSource { margin-left: 3em; padding-left: 4px; }
52
+ div.sourceCode
53
+ { }
54
+ @media screen {
55
+ pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
56
+ }
57
+ </style>
58
+
59
+
60
+ <script src="site_libs/quarto-nav/quarto-nav.js"></script>
61
+ <script src="site_libs/quarto-nav/headroom.min.js"></script>
62
+ <script src="site_libs/clipboard/clipboard.min.js"></script>
63
+ <script src="site_libs/quarto-search/autocomplete.umd.js"></script>
64
+ <script src="site_libs/quarto-search/fuse.min.js"></script>
65
+ <script src="site_libs/quarto-search/quarto-search.js"></script>
66
+ <meta name="quarto:offset" content="./">
67
+ <link href="./cw011removeChar.html" rel="next">
68
+ <link href="./cw009number_to_string.html" rel="prev">
69
+ <link href="./logo.png" rel="icon" type="image/png">
70
+ <script src="site_libs/quarto-html/quarto.js"></script>
71
+ <script src="site_libs/quarto-html/popper.min.js"></script>
72
+ <script src="site_libs/quarto-html/tippy.umd.min.js"></script>
73
+ <script src="site_libs/quarto-html/anchor.min.js"></script>
74
+ <link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
75
+ <link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
76
+ <script src="site_libs/bootstrap/bootstrap.min.js"></script>
77
+ <link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
78
+ <link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
79
+ <link href="site_libs/quarto-contrib/badge/badge.css" rel="stylesheet">
80
+ <script id="quarto-search-options" type="application/json">{
81
+ "location": "sidebar",
82
+ "copy-button": false,
83
+ "collapse-after": 3,
84
+ "panel-placement": "start",
85
+ "type": "textbox",
86
+ "limit": 20,
87
+ "language": {
88
+ "search-no-results-text": "No results",
89
+ "search-matching-documents-text": "matching documents",
90
+ "search-copy-link-title": "Copy link to search",
91
+ "search-hide-matches-text": "Hide additional matches",
92
+ "search-more-match-text": "more match in this document",
93
+ "search-more-matches-text": "more matches in this document",
94
+ "search-clear-button-title": "Clear",
95
+ "search-detached-cancel-button-title": "Cancel",
96
+ "search-submit-button-title": "Submit",
97
+ "search-label": "Search"
98
+ }
99
+ }</script>
100
+
101
+
102
+ <meta name="twitter:title" content="Codewars Challenge 2024 Menggunakan R dan RStudio - 10&nbsp; Opposite number">
103
+ <meta name="twitter:description" content="">
104
+ <meta name="twitter:image" content="https://huggingface.co/spaces/aephidayatuloh/codewars2024/new_starcore_logo.png">
105
+ <meta name="twitter:image-height" content="434">
106
+ <meta name="twitter:image-width" content="1946">
107
+ <meta name="twitter:card" content="summary_large_image">
108
+ </head>
109
+
110
+ <body class="nav-sidebar floating">
111
+
112
+ <div id="quarto-search-results"></div>
113
+ <header id="quarto-header" class="headroom fixed-top">
114
+ <nav class="quarto-secondary-nav">
115
+ <div class="container-fluid d-flex">
116
+ <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
117
+ <i class="bi bi-layout-text-sidebar-reverse"></i>
118
+ </button>
119
+ <nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./cw010opposite.html"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></a></li></ol></nav>
120
+ <a class="flex-grow-1" role="button" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
121
+ </a>
122
+ <button type="button" class="btn quarto-search-button" aria-label="" onclick="window.quartoOpenSearch();">
123
+ <i class="bi bi-search"></i>
124
+ </button>
125
+ </div>
126
+ </nav>
127
+ </header>
128
+ <!-- content -->
129
+ <div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
130
+ <!-- sidebar -->
131
+ <nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal sidebar-navigation floating overflow-auto">
132
+ <div class="pt-lg-2 mt-2 text-left sidebar-header">
133
+ <div class="sidebar-title mb-0 py-0">
134
+ <a href="./">Codewars Challenge 2024 Menggunakan R dan RStudio</a>
135
+ <div class="sidebar-tools-main">
136
+ <a href="https://huggingface.co/spaces/aephidayatuloh/codewars2024/tree/main" rel="" title="Source Code" class="quarto-navigation-tool px-1" aria-label="Source Code"><i class="bi bi-git"></i></a>
137
+ </div>
138
+ </div>
139
+ </div>
140
+ <div class="mt-2 flex-shrink-0 align-items-center">
141
+ <div class="sidebar-search">
142
+ <div id="quarto-search" class="" title="Search"></div>
143
+ </div>
144
+ </div>
145
+ <div class="sidebar-menu-container">
146
+ <ul class="list-unstyled mt-1">
147
+ <li class="sidebar-item">
148
+ <div class="sidebar-item-container">
149
+ <a href="./index.html" class="sidebar-item-text sidebar-link">
150
+ <span class="menu-text">Pengantar</span></a>
151
+ </div>
152
+ </li>
153
+ <li class="sidebar-item">
154
+ <div class="sidebar-item-container">
155
+ <a href="./cw001evenodd.html" class="sidebar-item-text sidebar-link">
156
+ <span class="menu-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span></span></a>
157
+ </div>
158
+ </li>
159
+ <li class="sidebar-item">
160
+ <div class="sidebar-item-container">
161
+ <a href="./cw002multiply.html" class="sidebar-item-text sidebar-link">
162
+ <span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span></span></a>
163
+ </div>
164
+ </li>
165
+ <li class="sidebar-item">
166
+ <div class="sidebar-item-container">
167
+ <a href="./cw003countsheep.html" class="sidebar-item-text sidebar-link">
168
+ <span class="menu-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">If you can’t sleep, just count sheep!!</span></span></a>
169
+ </div>
170
+ </li>
171
+ <li class="sidebar-item">
172
+ <div class="sidebar-item-container">
173
+ <a href="./cw004reducegrow.html" class="sidebar-item-text sidebar-link">
174
+ <span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow</span></span></a>
175
+ </div>
176
+ </li>
177
+ <li class="sidebar-item">
178
+ <div class="sidebar-item-container">
179
+ <a href="./cw005make_negative.html" class="sidebar-item-text sidebar-link">
180
+ <span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Return Negative</span></span></a>
181
+ </div>
182
+ </li>
183
+ <li class="sidebar-item">
184
+ <div class="sidebar-item-container">
185
+ <a href="./cw006positive_sum.html" class="sidebar-item-text sidebar-link">
186
+ <span class="menu-text"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Sum of positive</span></span></a>
187
+ </div>
188
+ </li>
189
+ <li class="sidebar-item">
190
+ <div class="sidebar-item-container">
191
+ <a href="./cw007reversedstrings.html" class="sidebar-item-text sidebar-link">
192
+ <span class="menu-text"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Reversed Strings</span></span></a>
193
+ </div>
194
+ </li>
195
+ <li class="sidebar-item">
196
+ <div class="sidebar-item-container">
197
+ <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
+ <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
+ </div>
200
+ </li>
201
+ <li class="sidebar-item">
202
+ <div class="sidebar-item-container">
203
+ <a href="./cw009number_to_string.html" class="sidebar-item-text sidebar-link">
204
+ <span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span></a>
205
+ </div>
206
+ </li>
207
+ <li class="sidebar-item">
208
+ <div class="sidebar-item-container">
209
+ <a href="./cw010opposite.html" class="sidebar-item-text sidebar-link active">
210
+ <span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span></a>
211
+ </div>
212
+ </li>
213
+ <li class="sidebar-item">
214
+ <div class="sidebar-item-container">
215
+ <a href="./cw011removeChar.html" class="sidebar-item-text sidebar-link">
216
+ <span class="menu-text"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Remove First and Last Character</span></span></a>
217
+ </div>
218
+ </li>
219
+ <li class="sidebar-item">
220
+ <div class="sidebar-item-container">
221
+ <a href="./cw012square_sum.html" class="sidebar-item-text sidebar-link">
222
+ <span class="menu-text"><span class="chapter-number">12</span>&nbsp; <span class="chapter-title">Square(n) Sum</span></span></a>
223
+ </div>
224
+ </li>
225
+ </ul>
226
+ </div>
227
+ </nav>
228
+ <div id="quarto-sidebar-glass" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass"></div>
229
+ <!-- margin-sidebar -->
230
+ <div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
231
+ <nav id="TOC" role="doc-toc" class="toc-active">
232
+ <h2 id="toc-title">Table of contents</h2>
233
+
234
+ <ul>
235
+ <li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">10.1</span> Instruction</a></li>
236
+ <li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">10.2</span> YouTube Video</a></li>
237
+ <li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">10.3</span> Solution Code</a></li>
238
+ <li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">10.4</span> Test</a></li>
239
+ <li><a href="#supported-by" id="toc-supported-by" class="nav-link" data-scroll-target="#supported-by"><span class="header-section-number">10.5</span> Supported by</a></li>
240
+ </ul>
241
+ </nav>
242
+ </div>
243
+ <!-- main -->
244
+ <main class="content" id="quarto-document-content">
245
+
246
+ <header id="title-block-header" class="quarto-title-block default">
247
+ <div class="quarto-title">
248
+ <h1 class="title"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></h1>
249
+ </div>
250
+
251
+
252
+
253
+ <div class="quarto-title-meta">
254
+
255
+
256
+
257
+
258
+ </div>
259
+
260
+
261
+ </header>
262
+
263
+ <p><span class="badge rounded-pill quarto-badge " style="background-color: grey;">8kyu</span> Tantangan #10/366 - 24 Feb 2024</p>
264
+ <p><a href="https://www.codewars.com/kata/56dec885c54a926dcd001095/train/r" class="uri">https://www.codewars.com/kata/56dec885c54a926dcd001095/train/r</a></p>
265
+ <section id="instruction" class="level2" data-number="10.1">
266
+ <h2 data-number="10.1" class="anchored" data-anchor-id="instruction"><span class="header-section-number">10.1</span> Instruction</h2>
267
+ <p>Very simple, given a number (integer / decimal / both depending on the language), find its opposite (additive inverse).</p>
268
+ <p>Examples:</p>
269
+ <pre><code>1: -1
270
+ 14: -14
271
+ -34: 34</code></pre>
272
+ </section>
273
+ <section id="youtube-video" class="level2" data-number="10.2">
274
+ <h2 data-number="10.2" class="anchored" data-anchor-id="youtube-video"><span class="header-section-number">10.2</span> YouTube Video</h2>
275
+ <div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/L8aczEhqymk?si=DSx84acpNvbkucrK" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
276
+ </section>
277
+ <section id="solution-code" class="level2" data-number="10.3">
278
+ <h2 data-number="10.3" class="anchored" data-anchor-id="solution-code"><span class="header-section-number">10.3</span> Solution Code</h2>
279
+ <div class="cell">
280
+ <div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>opposite <span class="ot">&lt;-</span> <span class="cf">function</span>(number){</span>
281
+ <span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="sc">-</span><span class="dv">1</span><span class="sc">*</span>number</span>
282
+ <span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
283
+ </div>
284
+ <div class="cell">
285
+ <div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>opposite <span class="ot">&lt;-</span> <span class="cf">function</span>(number)<span class="sc">-</span>number</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
286
+ </div>
287
+ </section>
288
+ <section id="test" class="level2" data-number="10.4">
289
+ <h2 data-number="10.4" class="anchored" data-anchor-id="test"><span class="header-section-number">10.4</span> Test</h2>
290
+ <div class="cell">
291
+ <div class="sourceCode cell-code" id="cb4"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(testthat)</span>
292
+ <span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
293
+ <span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">"the opposite of positive 1 is negative 1"</span>, {</span>
294
+ <span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">opposite</span>(<span class="dv">1</span>), <span class="sc">-</span><span class="dv">1</span>)</span>
295
+ <span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
296
+ <div class="cell-output cell-output-stdout">
297
+ <pre><code>Test passed 🥇</code></pre>
298
+ </div>
299
+ <div class="sourceCode cell-code" id="cb6"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">"the opposite of 0 is 0"</span>, {</span>
300
+ <span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">opposite</span>(<span class="dv">0</span>), <span class="dv">0</span>)</span>
301
+ <span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
302
+ <div class="cell-output cell-output-stdout">
303
+ <pre><code>Test passed 🎊</code></pre>
304
+ </div>
305
+ <div class="sourceCode cell-code" id="cb8"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">"the opposite of positive 3.14 is negative 3.14"</span>, {</span>
306
+ <span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">opposite</span>(<span class="fl">3.14</span>), <span class="sc">-</span><span class="fl">3.14</span>)</span>
307
+ <span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
308
+ <div class="cell-output cell-output-stdout">
309
+ <pre><code>Test passed 🎉</code></pre>
310
+ </div>
311
+ <div class="sourceCode cell-code" id="cb10"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">"the opposite of negative 400.2 is positive 400.2"</span>, {</span>
312
+ <span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">opposite</span>(<span class="sc">-</span><span class="fl">400.2</span>), <span class="fl">400.2</span>)</span>
313
+ <span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
314
+ <div class="cell-output cell-output-stdout">
315
+ <pre><code>Test passed 🥳</code></pre>
316
+ </div>
317
+ </div>
318
+ </section>
319
+ <section id="supported-by" class="level2" data-number="10.5">
320
+ <h2 data-number="10.5" class="anchored" data-anchor-id="supported-by"><span class="header-section-number">10.5</span> Supported by</h2>
321
+ <div class="quarto-figure quarto-figure-center">
322
+ <figure class="figure">
323
+ <p><a href="https://www.starcore.co"><img src="new_starcore_logo.png" class="img-fluid figure-img"></a></p>
324
+ <figcaption class="figure-caption">StarCore Analytics</figcaption>
325
+ </figure>
326
+ </div>
327
+
328
+
329
+ </section>
330
+
331
+ </main> <!-- /main -->
332
+ <script id="quarto-html-after-body" type="application/javascript">
333
+ window.document.addEventListener("DOMContentLoaded", function (event) {
334
+ const toggleBodyColorMode = (bsSheetEl) => {
335
+ const mode = bsSheetEl.getAttribute("data-mode");
336
+ const bodyEl = window.document.querySelector("body");
337
+ if (mode === "dark") {
338
+ bodyEl.classList.add("quarto-dark");
339
+ bodyEl.classList.remove("quarto-light");
340
+ } else {
341
+ bodyEl.classList.add("quarto-light");
342
+ bodyEl.classList.remove("quarto-dark");
343
+ }
344
+ }
345
+ const toggleBodyColorPrimary = () => {
346
+ const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
347
+ if (bsSheetEl) {
348
+ toggleBodyColorMode(bsSheetEl);
349
+ }
350
+ }
351
+ toggleBodyColorPrimary();
352
+ const icon = "";
353
+ const anchorJS = new window.AnchorJS();
354
+ anchorJS.options = {
355
+ placement: 'right',
356
+ icon: icon
357
+ };
358
+ anchorJS.add('.anchored');
359
+ const isCodeAnnotation = (el) => {
360
+ for (const clz of el.classList) {
361
+ if (clz.startsWith('code-annotation-')) {
362
+ return true;
363
+ }
364
+ }
365
+ return false;
366
+ }
367
+ const clipboard = new window.ClipboardJS('.code-copy-button', {
368
+ text: function(trigger) {
369
+ const codeEl = trigger.previousElementSibling.cloneNode(true);
370
+ for (const childEl of codeEl.children) {
371
+ if (isCodeAnnotation(childEl)) {
372
+ childEl.remove();
373
+ }
374
+ }
375
+ return codeEl.innerText;
376
+ }
377
+ });
378
+ clipboard.on('success', function(e) {
379
+ // button target
380
+ const button = e.trigger;
381
+ // don't keep focus
382
+ button.blur();
383
+ // flash "checked"
384
+ button.classList.add('code-copy-button-checked');
385
+ var currentTitle = button.getAttribute("title");
386
+ button.setAttribute("title", "Copied!");
387
+ let tooltip;
388
+ if (window.bootstrap) {
389
+ button.setAttribute("data-bs-toggle", "tooltip");
390
+ button.setAttribute("data-bs-placement", "left");
391
+ button.setAttribute("data-bs-title", "Copied!");
392
+ tooltip = new bootstrap.Tooltip(button,
393
+ { trigger: "manual",
394
+ customClass: "code-copy-button-tooltip",
395
+ offset: [0, -8]});
396
+ tooltip.show();
397
+ }
398
+ setTimeout(function() {
399
+ if (tooltip) {
400
+ tooltip.hide();
401
+ button.removeAttribute("data-bs-title");
402
+ button.removeAttribute("data-bs-toggle");
403
+ button.removeAttribute("data-bs-placement");
404
+ }
405
+ button.setAttribute("title", currentTitle);
406
+ button.classList.remove('code-copy-button-checked');
407
+ }, 1000);
408
+ // clear code selection
409
+ e.clearSelection();
410
+ });
411
+ function tippyHover(el, contentFn) {
412
+ const config = {
413
+ allowHTML: true,
414
+ content: contentFn,
415
+ maxWidth: 500,
416
+ delay: 100,
417
+ arrow: false,
418
+ appendTo: function(el) {
419
+ return el.parentElement;
420
+ },
421
+ interactive: true,
422
+ interactiveBorder: 10,
423
+ theme: 'quarto',
424
+ placement: 'bottom-start'
425
+ };
426
+ window.tippy(el, config);
427
+ }
428
+ const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
429
+ for (var i=0; i<noterefs.length; i++) {
430
+ const ref = noterefs[i];
431
+ tippyHover(ref, function() {
432
+ // use id or data attribute instead here
433
+ let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
434
+ try { href = new URL(href).hash; } catch {}
435
+ const id = href.replace(/^#\/?/, "");
436
+ const note = window.document.getElementById(id);
437
+ return note.innerHTML;
438
+ });
439
+ }
440
+ let selectedAnnoteEl;
441
+ const selectorForAnnotation = ( cell, annotation) => {
442
+ let cellAttr = 'data-code-cell="' + cell + '"';
443
+ let lineAttr = 'data-code-annotation="' + annotation + '"';
444
+ const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
445
+ return selector;
446
+ }
447
+ const selectCodeLines = (annoteEl) => {
448
+ const doc = window.document;
449
+ const targetCell = annoteEl.getAttribute("data-target-cell");
450
+ const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
451
+ const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
452
+ const lines = annoteSpan.getAttribute("data-code-lines").split(",");
453
+ const lineIds = lines.map((line) => {
454
+ return targetCell + "-" + line;
455
+ })
456
+ let top = null;
457
+ let height = null;
458
+ let parent = null;
459
+ if (lineIds.length > 0) {
460
+ //compute the position of the single el (top and bottom and make a div)
461
+ const el = window.document.getElementById(lineIds[0]);
462
+ top = el.offsetTop;
463
+ height = el.offsetHeight;
464
+ parent = el.parentElement.parentElement;
465
+ if (lineIds.length > 1) {
466
+ const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
467
+ const bottom = lastEl.offsetTop + lastEl.offsetHeight;
468
+ height = bottom - top;
469
+ }
470
+ if (top !== null && height !== null && parent !== null) {
471
+ // cook up a div (if necessary) and position it
472
+ let div = window.document.getElementById("code-annotation-line-highlight");
473
+ if (div === null) {
474
+ div = window.document.createElement("div");
475
+ div.setAttribute("id", "code-annotation-line-highlight");
476
+ div.style.position = 'absolute';
477
+ parent.appendChild(div);
478
+ }
479
+ div.style.top = top - 2 + "px";
480
+ div.style.height = height + 4 + "px";
481
+ let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
482
+ if (gutterDiv === null) {
483
+ gutterDiv = window.document.createElement("div");
484
+ gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
485
+ gutterDiv.style.position = 'absolute';
486
+ const codeCell = window.document.getElementById(targetCell);
487
+ const gutter = codeCell.querySelector('.code-annotation-gutter');
488
+ gutter.appendChild(gutterDiv);
489
+ }
490
+ gutterDiv.style.top = top - 2 + "px";
491
+ gutterDiv.style.height = height + 4 + "px";
492
+ }
493
+ selectedAnnoteEl = annoteEl;
494
+ }
495
+ };
496
+ const unselectCodeLines = () => {
497
+ const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
498
+ elementsIds.forEach((elId) => {
499
+ const div = window.document.getElementById(elId);
500
+ if (div) {
501
+ div.remove();
502
+ }
503
+ });
504
+ selectedAnnoteEl = undefined;
505
+ };
506
+ // Attach click handler to the DT
507
+ const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
508
+ for (const annoteDlNode of annoteDls) {
509
+ annoteDlNode.addEventListener('click', (event) => {
510
+ const clickedEl = event.target;
511
+ if (clickedEl !== selectedAnnoteEl) {
512
+ unselectCodeLines();
513
+ const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
514
+ if (activeEl) {
515
+ activeEl.classList.remove('code-annotation-active');
516
+ }
517
+ selectCodeLines(clickedEl);
518
+ clickedEl.classList.add('code-annotation-active');
519
+ } else {
520
+ // Unselect the line
521
+ unselectCodeLines();
522
+ clickedEl.classList.remove('code-annotation-active');
523
+ }
524
+ });
525
+ }
526
+ const findCites = (el) => {
527
+ const parentEl = el.parentElement;
528
+ if (parentEl) {
529
+ const cites = parentEl.dataset.cites;
530
+ if (cites) {
531
+ return {
532
+ el,
533
+ cites: cites.split(' ')
534
+ };
535
+ } else {
536
+ return findCites(el.parentElement)
537
+ }
538
+ } else {
539
+ return undefined;
540
+ }
541
+ };
542
+ var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
543
+ for (var i=0; i<bibliorefs.length; i++) {
544
+ const ref = bibliorefs[i];
545
+ const citeInfo = findCites(ref);
546
+ if (citeInfo) {
547
+ tippyHover(citeInfo.el, function() {
548
+ var popup = window.document.createElement('div');
549
+ citeInfo.cites.forEach(function(cite) {
550
+ var citeDiv = window.document.createElement('div');
551
+ citeDiv.classList.add('hanging-indent');
552
+ citeDiv.classList.add('csl-entry');
553
+ var biblioDiv = window.document.getElementById('ref-' + cite);
554
+ if (biblioDiv) {
555
+ citeDiv.innerHTML = biblioDiv.innerHTML;
556
+ }
557
+ popup.appendChild(citeDiv);
558
+ });
559
+ return popup.innerHTML;
560
+ });
561
+ }
562
+ }
563
+ });
564
+ </script>
565
+ <nav class="page-navigation">
566
+ <div class="nav-page nav-page-previous">
567
+ <a href="./cw009number_to_string.html" class="pagination-link">
568
+ <i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span>
569
+ </a>
570
+ </div>
571
+ <div class="nav-page nav-page-next">
572
+ <a href="./cw011removeChar.html" class="pagination-link">
573
+ <span class="nav-page-text"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Remove First and Last Character</span></span> <i class="bi bi-arrow-right-short"></i>
574
+ </a>
575
+ </div>
576
+ </nav>
577
+ </div> <!-- /content -->
578
+
579
+
580
+
581
+ </body></html>
cw011removeChar.html ADDED
@@ -0,0 +1,566 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.3.433">
6
+
7
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
8
+
9
+
10
+ <title>Codewars Challenge 2024 Menggunakan R dan RStudio - 11&nbsp; Remove First and Last Character</title>
11
+ <style>
12
+ code{white-space: pre-wrap;}
13
+ span.smallcaps{font-variant: small-caps;}
14
+ div.columns{display: flex; gap: min(4vw, 1.5em);}
15
+ div.column{flex: auto; overflow-x: auto;}
16
+ div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
17
+ ul.task-list{list-style: none;}
18
+ ul.task-list li input[type="checkbox"] {
19
+ width: 0.8em;
20
+ margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
21
+ vertical-align: middle;
22
+ }
23
+ /* CSS for syntax highlighting */
24
+ pre > code.sourceCode { white-space: pre; position: relative; }
25
+ pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
26
+ pre > code.sourceCode > span:empty { height: 1.2em; }
27
+ .sourceCode { overflow: visible; }
28
+ code.sourceCode > span { color: inherit; text-decoration: inherit; }
29
+ div.sourceCode { margin: 1em 0; }
30
+ pre.sourceCode { margin: 0; }
31
+ @media screen {
32
+ div.sourceCode { overflow: auto; }
33
+ }
34
+ @media print {
35
+ pre > code.sourceCode { white-space: pre-wrap; }
36
+ pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
37
+ }
38
+ pre.numberSource code
39
+ { counter-reset: source-line 0; }
40
+ pre.numberSource code > span
41
+ { position: relative; left: -4em; counter-increment: source-line; }
42
+ pre.numberSource code > span > a:first-child::before
43
+ { content: counter(source-line);
44
+ position: relative; left: -1em; text-align: right; vertical-align: baseline;
45
+ border: none; display: inline-block;
46
+ -webkit-touch-callout: none; -webkit-user-select: none;
47
+ -khtml-user-select: none; -moz-user-select: none;
48
+ -ms-user-select: none; user-select: none;
49
+ padding: 0 4px; width: 4em;
50
+ }
51
+ pre.numberSource { margin-left: 3em; padding-left: 4px; }
52
+ div.sourceCode
53
+ { }
54
+ @media screen {
55
+ pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
56
+ }
57
+ </style>
58
+
59
+
60
+ <script src="site_libs/quarto-nav/quarto-nav.js"></script>
61
+ <script src="site_libs/quarto-nav/headroom.min.js"></script>
62
+ <script src="site_libs/clipboard/clipboard.min.js"></script>
63
+ <script src="site_libs/quarto-search/autocomplete.umd.js"></script>
64
+ <script src="site_libs/quarto-search/fuse.min.js"></script>
65
+ <script src="site_libs/quarto-search/quarto-search.js"></script>
66
+ <meta name="quarto:offset" content="./">
67
+ <link href="./cw012square_sum.html" rel="next">
68
+ <link href="./cw010opposite.html" rel="prev">
69
+ <link href="./logo.png" rel="icon" type="image/png">
70
+ <script src="site_libs/quarto-html/quarto.js"></script>
71
+ <script src="site_libs/quarto-html/popper.min.js"></script>
72
+ <script src="site_libs/quarto-html/tippy.umd.min.js"></script>
73
+ <script src="site_libs/quarto-html/anchor.min.js"></script>
74
+ <link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
75
+ <link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
76
+ <script src="site_libs/bootstrap/bootstrap.min.js"></script>
77
+ <link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
78
+ <link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
79
+ <link href="site_libs/quarto-contrib/badge/badge.css" rel="stylesheet">
80
+ <script id="quarto-search-options" type="application/json">{
81
+ "location": "sidebar",
82
+ "copy-button": false,
83
+ "collapse-after": 3,
84
+ "panel-placement": "start",
85
+ "type": "textbox",
86
+ "limit": 20,
87
+ "language": {
88
+ "search-no-results-text": "No results",
89
+ "search-matching-documents-text": "matching documents",
90
+ "search-copy-link-title": "Copy link to search",
91
+ "search-hide-matches-text": "Hide additional matches",
92
+ "search-more-match-text": "more match in this document",
93
+ "search-more-matches-text": "more matches in this document",
94
+ "search-clear-button-title": "Clear",
95
+ "search-detached-cancel-button-title": "Cancel",
96
+ "search-submit-button-title": "Submit",
97
+ "search-label": "Search"
98
+ }
99
+ }</script>
100
+
101
+
102
+ <meta name="twitter:title" content="Codewars Challenge 2024 Menggunakan R dan RStudio - 11&nbsp; Remove First and Last Character">
103
+ <meta name="twitter:description" content="">
104
+ <meta name="twitter:image" content="https://huggingface.co/spaces/aephidayatuloh/codewars2024/new_starcore_logo.png">
105
+ <meta name="twitter:image-height" content="434">
106
+ <meta name="twitter:image-width" content="1946">
107
+ <meta name="twitter:card" content="summary_large_image">
108
+ </head>
109
+
110
+ <body class="nav-sidebar floating">
111
+
112
+ <div id="quarto-search-results"></div>
113
+ <header id="quarto-header" class="headroom fixed-top">
114
+ <nav class="quarto-secondary-nav">
115
+ <div class="container-fluid d-flex">
116
+ <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
117
+ <i class="bi bi-layout-text-sidebar-reverse"></i>
118
+ </button>
119
+ <nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./cw011removeChar.html"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Remove First and Last Character</span></a></li></ol></nav>
120
+ <a class="flex-grow-1" role="button" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
121
+ </a>
122
+ <button type="button" class="btn quarto-search-button" aria-label="" onclick="window.quartoOpenSearch();">
123
+ <i class="bi bi-search"></i>
124
+ </button>
125
+ </div>
126
+ </nav>
127
+ </header>
128
+ <!-- content -->
129
+ <div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
130
+ <!-- sidebar -->
131
+ <nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal sidebar-navigation floating overflow-auto">
132
+ <div class="pt-lg-2 mt-2 text-left sidebar-header">
133
+ <div class="sidebar-title mb-0 py-0">
134
+ <a href="./">Codewars Challenge 2024 Menggunakan R dan RStudio</a>
135
+ <div class="sidebar-tools-main">
136
+ <a href="https://huggingface.co/spaces/aephidayatuloh/codewars2024/tree/main" rel="" title="Source Code" class="quarto-navigation-tool px-1" aria-label="Source Code"><i class="bi bi-git"></i></a>
137
+ </div>
138
+ </div>
139
+ </div>
140
+ <div class="mt-2 flex-shrink-0 align-items-center">
141
+ <div class="sidebar-search">
142
+ <div id="quarto-search" class="" title="Search"></div>
143
+ </div>
144
+ </div>
145
+ <div class="sidebar-menu-container">
146
+ <ul class="list-unstyled mt-1">
147
+ <li class="sidebar-item">
148
+ <div class="sidebar-item-container">
149
+ <a href="./index.html" class="sidebar-item-text sidebar-link">
150
+ <span class="menu-text">Pengantar</span></a>
151
+ </div>
152
+ </li>
153
+ <li class="sidebar-item">
154
+ <div class="sidebar-item-container">
155
+ <a href="./cw001evenodd.html" class="sidebar-item-text sidebar-link">
156
+ <span class="menu-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span></span></a>
157
+ </div>
158
+ </li>
159
+ <li class="sidebar-item">
160
+ <div class="sidebar-item-container">
161
+ <a href="./cw002multiply.html" class="sidebar-item-text sidebar-link">
162
+ <span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span></span></a>
163
+ </div>
164
+ </li>
165
+ <li class="sidebar-item">
166
+ <div class="sidebar-item-container">
167
+ <a href="./cw003countsheep.html" class="sidebar-item-text sidebar-link">
168
+ <span class="menu-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">If you can’t sleep, just count sheep!!</span></span></a>
169
+ </div>
170
+ </li>
171
+ <li class="sidebar-item">
172
+ <div class="sidebar-item-container">
173
+ <a href="./cw004reducegrow.html" class="sidebar-item-text sidebar-link">
174
+ <span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow</span></span></a>
175
+ </div>
176
+ </li>
177
+ <li class="sidebar-item">
178
+ <div class="sidebar-item-container">
179
+ <a href="./cw005make_negative.html" class="sidebar-item-text sidebar-link">
180
+ <span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Return Negative</span></span></a>
181
+ </div>
182
+ </li>
183
+ <li class="sidebar-item">
184
+ <div class="sidebar-item-container">
185
+ <a href="./cw006positive_sum.html" class="sidebar-item-text sidebar-link">
186
+ <span class="menu-text"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Sum of positive</span></span></a>
187
+ </div>
188
+ </li>
189
+ <li class="sidebar-item">
190
+ <div class="sidebar-item-container">
191
+ <a href="./cw007reversedstrings.html" class="sidebar-item-text sidebar-link">
192
+ <span class="menu-text"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Reversed Strings</span></span></a>
193
+ </div>
194
+ </li>
195
+ <li class="sidebar-item">
196
+ <div class="sidebar-item-container">
197
+ <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
198
+ <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
199
+ </div>
200
+ </li>
201
+ <li class="sidebar-item">
202
+ <div class="sidebar-item-container">
203
+ <a href="./cw009number_to_string.html" class="sidebar-item-text sidebar-link">
204
+ <span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span></a>
205
+ </div>
206
+ </li>
207
+ <li class="sidebar-item">
208
+ <div class="sidebar-item-container">
209
+ <a href="./cw010opposite.html" class="sidebar-item-text sidebar-link">
210
+ <span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span></a>
211
+ </div>
212
+ </li>
213
+ <li class="sidebar-item">
214
+ <div class="sidebar-item-container">
215
+ <a href="./cw011removeChar.html" class="sidebar-item-text sidebar-link active">
216
+ <span class="menu-text"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Remove First and Last Character</span></span></a>
217
+ </div>
218
+ </li>
219
+ <li class="sidebar-item">
220
+ <div class="sidebar-item-container">
221
+ <a href="./cw012square_sum.html" class="sidebar-item-text sidebar-link">
222
+ <span class="menu-text"><span class="chapter-number">12</span>&nbsp; <span class="chapter-title">Remove First and Last Character</span></span></a>
223
+ </div>
224
+ </li>
225
+ </ul>
226
+ </div>
227
+ </nav>
228
+ <div id="quarto-sidebar-glass" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass"></div>
229
+ <!-- margin-sidebar -->
230
+ <div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
231
+ <nav id="TOC" role="doc-toc" class="toc-active">
232
+ <h2 id="toc-title">Table of contents</h2>
233
+
234
+ <ul>
235
+ <li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">11.1</span> Instruction</a></li>
236
+ <li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">11.2</span> YouTube Video</a></li>
237
+ <li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">11.3</span> Solution Code</a></li>
238
+ <li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">11.4</span> Test</a></li>
239
+ <li><a href="#supported-by" id="toc-supported-by" class="nav-link" data-scroll-target="#supported-by"><span class="header-section-number">11.5</span> Supported by</a></li>
240
+ </ul>
241
+ </nav>
242
+ </div>
243
+ <!-- main -->
244
+ <main class="content" id="quarto-document-content">
245
+
246
+ <header id="title-block-header" class="quarto-title-block default">
247
+ <div class="quarto-title">
248
+ <h1 class="title"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Remove First and Last Character</span></h1>
249
+ </div>
250
+
251
+
252
+
253
+ <div class="quarto-title-meta">
254
+
255
+
256
+
257
+
258
+ </div>
259
+
260
+
261
+ </header>
262
+
263
+ <p><span class="badge rounded-pill quarto-badge " style="background-color: grey;">8kyu</span> Tantangan #11/366 - 25 Feb 2024</p>
264
+ <p><a href="https://www.codewars.com/kata/56bc28ad5bdaeb48760009b0/train/r" class="uri">https://www.codewars.com/kata/56bc28ad5bdaeb48760009b0/train/r</a></p>
265
+ <section id="instruction" class="level2" data-number="11.1">
266
+ <h2 data-number="11.1" class="anchored" data-anchor-id="instruction"><span class="header-section-number">11.1</span> Instruction</h2>
267
+ <p>It’s pretty straightforward. Your goal is to create a function that removes the first and last characters of a string. You’re given one parameter, the original string. You don’t have to worry about strings with less than two characters.</p>
268
+ </section>
269
+ <section id="youtube-video" class="level2" data-number="11.2">
270
+ <h2 data-number="11.2" class="anchored" data-anchor-id="youtube-video"><span class="header-section-number">11.2</span> YouTube Video</h2>
271
+ <div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/L8aczEhqymk?si=DSx84acpNvbkucrK" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
272
+ </section>
273
+ <section id="solution-code" class="level2" data-number="11.3">
274
+ <h2 data-number="11.3" class="anchored" data-anchor-id="solution-code"><span class="header-section-number">11.3</span> Solution Code</h2>
275
+ <div class="cell">
276
+ <div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>removeChar <span class="ot">&lt;-</span> <span class="cf">function</span>(str){</span>
277
+ <span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> char <span class="ot">&lt;-</span> <span class="fu">unlist</span>(<span class="fu">strsplit</span>(str, <span class="st">""</span>))</span>
278
+ <span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> char_removed <span class="ot">&lt;-</span> char[<span class="sc">-</span><span class="fu">c</span>(<span class="dv">1</span>,<span class="fu">length</span>(char))]</span>
279
+ <span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">paste</span>(char_removed, <span class="at">collapse =</span> <span class="st">""</span>)</span>
280
+ <span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
281
+ </div>
282
+ <div class="cell">
283
+ <div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>removeChar <span class="ot">&lt;-</span> <span class="cf">function</span>(str){</span>
284
+ <span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">substr</span>(str, <span class="dv">2</span>, <span class="fu">nchar</span>(str)<span class="sc">-</span><span class="dv">1</span>)</span>
285
+ <span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
286
+ </div>
287
+ </section>
288
+ <section id="test" class="level2" data-number="11.4">
289
+ <h2 data-number="11.4" class="anchored" data-anchor-id="test"><span class="header-section-number">11.4</span> Test</h2>
290
+ <div class="cell">
291
+ <div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(testthat)</span>
292
+ <span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
293
+ <span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">'basic tests'</span>, {</span>
294
+ <span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">removeChar</span>(<span class="st">'eloquent'</span>), <span class="st">'loquen'</span>)</span>
295
+ <span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">removeChar</span>(<span class="st">'country'</span>), <span class="st">'ountr'</span>)</span>
296
+ <span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">removeChar</span>(<span class="st">'person'</span>), <span class="st">'erso'</span>)</span>
297
+ <span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">removeChar</span>(<span class="st">'place'</span>), <span class="st">'lac'</span>)</span>
298
+ <span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
299
+ <div class="cell-output cell-output-stdout">
300
+ <pre><code>Test passed 😸</code></pre>
301
+ </div>
302
+ </div>
303
+ </section>
304
+ <section id="supported-by" class="level2" data-number="11.5">
305
+ <h2 data-number="11.5" class="anchored" data-anchor-id="supported-by"><span class="header-section-number">11.5</span> Supported by</h2>
306
+ <div class="quarto-figure quarto-figure-center">
307
+ <figure class="figure">
308
+ <p><a href="https://www.starcore.co"><img src="new_starcore_logo.png" class="img-fluid figure-img"></a></p>
309
+ <figcaption class="figure-caption">StarCore Analytics</figcaption>
310
+ </figure>
311
+ </div>
312
+
313
+
314
+ </section>
315
+
316
+ </main> <!-- /main -->
317
+ <script id="quarto-html-after-body" type="application/javascript">
318
+ window.document.addEventListener("DOMContentLoaded", function (event) {
319
+ const toggleBodyColorMode = (bsSheetEl) => {
320
+ const mode = bsSheetEl.getAttribute("data-mode");
321
+ const bodyEl = window.document.querySelector("body");
322
+ if (mode === "dark") {
323
+ bodyEl.classList.add("quarto-dark");
324
+ bodyEl.classList.remove("quarto-light");
325
+ } else {
326
+ bodyEl.classList.add("quarto-light");
327
+ bodyEl.classList.remove("quarto-dark");
328
+ }
329
+ }
330
+ const toggleBodyColorPrimary = () => {
331
+ const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
332
+ if (bsSheetEl) {
333
+ toggleBodyColorMode(bsSheetEl);
334
+ }
335
+ }
336
+ toggleBodyColorPrimary();
337
+ const icon = "";
338
+ const anchorJS = new window.AnchorJS();
339
+ anchorJS.options = {
340
+ placement: 'right',
341
+ icon: icon
342
+ };
343
+ anchorJS.add('.anchored');
344
+ const isCodeAnnotation = (el) => {
345
+ for (const clz of el.classList) {
346
+ if (clz.startsWith('code-annotation-')) {
347
+ return true;
348
+ }
349
+ }
350
+ return false;
351
+ }
352
+ const clipboard = new window.ClipboardJS('.code-copy-button', {
353
+ text: function(trigger) {
354
+ const codeEl = trigger.previousElementSibling.cloneNode(true);
355
+ for (const childEl of codeEl.children) {
356
+ if (isCodeAnnotation(childEl)) {
357
+ childEl.remove();
358
+ }
359
+ }
360
+ return codeEl.innerText;
361
+ }
362
+ });
363
+ clipboard.on('success', function(e) {
364
+ // button target
365
+ const button = e.trigger;
366
+ // don't keep focus
367
+ button.blur();
368
+ // flash "checked"
369
+ button.classList.add('code-copy-button-checked');
370
+ var currentTitle = button.getAttribute("title");
371
+ button.setAttribute("title", "Copied!");
372
+ let tooltip;
373
+ if (window.bootstrap) {
374
+ button.setAttribute("data-bs-toggle", "tooltip");
375
+ button.setAttribute("data-bs-placement", "left");
376
+ button.setAttribute("data-bs-title", "Copied!");
377
+ tooltip = new bootstrap.Tooltip(button,
378
+ { trigger: "manual",
379
+ customClass: "code-copy-button-tooltip",
380
+ offset: [0, -8]});
381
+ tooltip.show();
382
+ }
383
+ setTimeout(function() {
384
+ if (tooltip) {
385
+ tooltip.hide();
386
+ button.removeAttribute("data-bs-title");
387
+ button.removeAttribute("data-bs-toggle");
388
+ button.removeAttribute("data-bs-placement");
389
+ }
390
+ button.setAttribute("title", currentTitle);
391
+ button.classList.remove('code-copy-button-checked');
392
+ }, 1000);
393
+ // clear code selection
394
+ e.clearSelection();
395
+ });
396
+ function tippyHover(el, contentFn) {
397
+ const config = {
398
+ allowHTML: true,
399
+ content: contentFn,
400
+ maxWidth: 500,
401
+ delay: 100,
402
+ arrow: false,
403
+ appendTo: function(el) {
404
+ return el.parentElement;
405
+ },
406
+ interactive: true,
407
+ interactiveBorder: 10,
408
+ theme: 'quarto',
409
+ placement: 'bottom-start'
410
+ };
411
+ window.tippy(el, config);
412
+ }
413
+ const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
414
+ for (var i=0; i<noterefs.length; i++) {
415
+ const ref = noterefs[i];
416
+ tippyHover(ref, function() {
417
+ // use id or data attribute instead here
418
+ let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
419
+ try { href = new URL(href).hash; } catch {}
420
+ const id = href.replace(/^#\/?/, "");
421
+ const note = window.document.getElementById(id);
422
+ return note.innerHTML;
423
+ });
424
+ }
425
+ let selectedAnnoteEl;
426
+ const selectorForAnnotation = ( cell, annotation) => {
427
+ let cellAttr = 'data-code-cell="' + cell + '"';
428
+ let lineAttr = 'data-code-annotation="' + annotation + '"';
429
+ const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
430
+ return selector;
431
+ }
432
+ const selectCodeLines = (annoteEl) => {
433
+ const doc = window.document;
434
+ const targetCell = annoteEl.getAttribute("data-target-cell");
435
+ const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
436
+ const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
437
+ const lines = annoteSpan.getAttribute("data-code-lines").split(",");
438
+ const lineIds = lines.map((line) => {
439
+ return targetCell + "-" + line;
440
+ })
441
+ let top = null;
442
+ let height = null;
443
+ let parent = null;
444
+ if (lineIds.length > 0) {
445
+ //compute the position of the single el (top and bottom and make a div)
446
+ const el = window.document.getElementById(lineIds[0]);
447
+ top = el.offsetTop;
448
+ height = el.offsetHeight;
449
+ parent = el.parentElement.parentElement;
450
+ if (lineIds.length > 1) {
451
+ const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
452
+ const bottom = lastEl.offsetTop + lastEl.offsetHeight;
453
+ height = bottom - top;
454
+ }
455
+ if (top !== null && height !== null && parent !== null) {
456
+ // cook up a div (if necessary) and position it
457
+ let div = window.document.getElementById("code-annotation-line-highlight");
458
+ if (div === null) {
459
+ div = window.document.createElement("div");
460
+ div.setAttribute("id", "code-annotation-line-highlight");
461
+ div.style.position = 'absolute';
462
+ parent.appendChild(div);
463
+ }
464
+ div.style.top = top - 2 + "px";
465
+ div.style.height = height + 4 + "px";
466
+ let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
467
+ if (gutterDiv === null) {
468
+ gutterDiv = window.document.createElement("div");
469
+ gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
470
+ gutterDiv.style.position = 'absolute';
471
+ const codeCell = window.document.getElementById(targetCell);
472
+ const gutter = codeCell.querySelector('.code-annotation-gutter');
473
+ gutter.appendChild(gutterDiv);
474
+ }
475
+ gutterDiv.style.top = top - 2 + "px";
476
+ gutterDiv.style.height = height + 4 + "px";
477
+ }
478
+ selectedAnnoteEl = annoteEl;
479
+ }
480
+ };
481
+ const unselectCodeLines = () => {
482
+ const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
483
+ elementsIds.forEach((elId) => {
484
+ const div = window.document.getElementById(elId);
485
+ if (div) {
486
+ div.remove();
487
+ }
488
+ });
489
+ selectedAnnoteEl = undefined;
490
+ };
491
+ // Attach click handler to the DT
492
+ const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
493
+ for (const annoteDlNode of annoteDls) {
494
+ annoteDlNode.addEventListener('click', (event) => {
495
+ const clickedEl = event.target;
496
+ if (clickedEl !== selectedAnnoteEl) {
497
+ unselectCodeLines();
498
+ const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
499
+ if (activeEl) {
500
+ activeEl.classList.remove('code-annotation-active');
501
+ }
502
+ selectCodeLines(clickedEl);
503
+ clickedEl.classList.add('code-annotation-active');
504
+ } else {
505
+ // Unselect the line
506
+ unselectCodeLines();
507
+ clickedEl.classList.remove('code-annotation-active');
508
+ }
509
+ });
510
+ }
511
+ const findCites = (el) => {
512
+ const parentEl = el.parentElement;
513
+ if (parentEl) {
514
+ const cites = parentEl.dataset.cites;
515
+ if (cites) {
516
+ return {
517
+ el,
518
+ cites: cites.split(' ')
519
+ };
520
+ } else {
521
+ return findCites(el.parentElement)
522
+ }
523
+ } else {
524
+ return undefined;
525
+ }
526
+ };
527
+ var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
528
+ for (var i=0; i<bibliorefs.length; i++) {
529
+ const ref = bibliorefs[i];
530
+ const citeInfo = findCites(ref);
531
+ if (citeInfo) {
532
+ tippyHover(citeInfo.el, function() {
533
+ var popup = window.document.createElement('div');
534
+ citeInfo.cites.forEach(function(cite) {
535
+ var citeDiv = window.document.createElement('div');
536
+ citeDiv.classList.add('hanging-indent');
537
+ citeDiv.classList.add('csl-entry');
538
+ var biblioDiv = window.document.getElementById('ref-' + cite);
539
+ if (biblioDiv) {
540
+ citeDiv.innerHTML = biblioDiv.innerHTML;
541
+ }
542
+ popup.appendChild(citeDiv);
543
+ });
544
+ return popup.innerHTML;
545
+ });
546
+ }
547
+ }
548
+ });
549
+ </script>
550
+ <nav class="page-navigation">
551
+ <div class="nav-page nav-page-previous">
552
+ <a href="./cw010opposite.html" class="pagination-link">
553
+ <i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span>
554
+ </a>
555
+ </div>
556
+ <div class="nav-page nav-page-next">
557
+ <a href="./cw012square_sum.html" class="pagination-link">
558
+ <span class="nav-page-text"><span class="chapter-number">12</span>&nbsp; <span class="chapter-title">Remove First and Last Character</span></span> <i class="bi bi-arrow-right-short"></i>
559
+ </a>
560
+ </div>
561
+ </nav>
562
+ </div> <!-- /content -->
563
+
564
+
565
+
566
+ </body></html>
cw012square_sum.html ADDED
@@ -0,0 +1,581 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.3.433">
6
+
7
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
8
+
9
+
10
+ <title>Codewars Challenge 2024 Menggunakan R dan RStudio - 12&nbsp; Square(n) Sum</title>
11
+ <style>
12
+ code{white-space: pre-wrap;}
13
+ span.smallcaps{font-variant: small-caps;}
14
+ div.columns{display: flex; gap: min(4vw, 1.5em);}
15
+ div.column{flex: auto; overflow-x: auto;}
16
+ div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
17
+ ul.task-list{list-style: none;}
18
+ ul.task-list li input[type="checkbox"] {
19
+ width: 0.8em;
20
+ margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
21
+ vertical-align: middle;
22
+ }
23
+ /* CSS for syntax highlighting */
24
+ pre > code.sourceCode { white-space: pre; position: relative; }
25
+ pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
26
+ pre > code.sourceCode > span:empty { height: 1.2em; }
27
+ .sourceCode { overflow: visible; }
28
+ code.sourceCode > span { color: inherit; text-decoration: inherit; }
29
+ div.sourceCode { margin: 1em 0; }
30
+ pre.sourceCode { margin: 0; }
31
+ @media screen {
32
+ div.sourceCode { overflow: auto; }
33
+ }
34
+ @media print {
35
+ pre > code.sourceCode { white-space: pre-wrap; }
36
+ pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
37
+ }
38
+ pre.numberSource code
39
+ { counter-reset: source-line 0; }
40
+ pre.numberSource code > span
41
+ { position: relative; left: -4em; counter-increment: source-line; }
42
+ pre.numberSource code > span > a:first-child::before
43
+ { content: counter(source-line);
44
+ position: relative; left: -1em; text-align: right; vertical-align: baseline;
45
+ border: none; display: inline-block;
46
+ -webkit-touch-callout: none; -webkit-user-select: none;
47
+ -khtml-user-select: none; -moz-user-select: none;
48
+ -ms-user-select: none; user-select: none;
49
+ padding: 0 4px; width: 4em;
50
+ }
51
+ pre.numberSource { margin-left: 3em; padding-left: 4px; }
52
+ div.sourceCode
53
+ { }
54
+ @media screen {
55
+ pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
56
+ }
57
+ </style>
58
+
59
+
60
+ <script src="site_libs/quarto-nav/quarto-nav.js"></script>
61
+ <script src="site_libs/quarto-nav/headroom.min.js"></script>
62
+ <script src="site_libs/clipboard/clipboard.min.js"></script>
63
+ <script src="site_libs/quarto-search/autocomplete.umd.js"></script>
64
+ <script src="site_libs/quarto-search/fuse.min.js"></script>
65
+ <script src="site_libs/quarto-search/quarto-search.js"></script>
66
+ <meta name="quarto:offset" content="./">
67
+ <link href="./cw011removeChar.html" rel="prev">
68
+ <link href="./logo.png" rel="icon" type="image/png">
69
+ <script src="site_libs/quarto-html/quarto.js"></script>
70
+ <script src="site_libs/quarto-html/popper.min.js"></script>
71
+ <script src="site_libs/quarto-html/tippy.umd.min.js"></script>
72
+ <script src="site_libs/quarto-html/anchor.min.js"></script>
73
+ <link href="site_libs/quarto-html/tippy.css" rel="stylesheet">
74
+ <link href="site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
75
+ <script src="site_libs/bootstrap/bootstrap.min.js"></script>
76
+ <link href="site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
77
+ <link href="site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
78
+ <link href="site_libs/quarto-contrib/badge/badge.css" rel="stylesheet">
79
+ <script id="quarto-search-options" type="application/json">{
80
+ "location": "sidebar",
81
+ "copy-button": false,
82
+ "collapse-after": 3,
83
+ "panel-placement": "start",
84
+ "type": "textbox",
85
+ "limit": 20,
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-detached-cancel-button-title": "Cancel",
95
+ "search-submit-button-title": "Submit",
96
+ "search-label": "Search"
97
+ }
98
+ }</script>
99
+
100
+ <script>window.backupDefine = window.define; window.define = undefined;</script><script src="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.js"></script>
101
+ <script>document.addEventListener("DOMContentLoaded", function () {
102
+ var mathElements = document.getElementsByClassName("math");
103
+ var macros = [];
104
+ for (var i = 0; i < mathElements.length; i++) {
105
+ var texText = mathElements[i].firstChild;
106
+ if (mathElements[i].tagName == "SPAN") {
107
+ katex.render(texText.data, mathElements[i], {
108
+ displayMode: mathElements[i].classList.contains('display'),
109
+ throwOnError: false,
110
+ macros: macros,
111
+ fleqn: false
112
+ });
113
+ }}});
114
+ </script>
115
+ <script>window.define = window.backupDefine; window.backupDefine = undefined;</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.1/dist/katex.min.css">
116
+
117
+ <meta name="twitter:title" content="Codewars Challenge 2024 Menggunakan R dan RStudio - 12&nbsp; Square(n) Sum">
118
+ <meta name="twitter:description" content="">
119
+ <meta name="twitter:image" content="https://huggingface.co/spaces/aephidayatuloh/codewars2024/new_starcore_logo.png">
120
+ <meta name="twitter:image-height" content="434">
121
+ <meta name="twitter:image-width" content="1946">
122
+ <meta name="twitter:card" content="summary_large_image">
123
+ </head>
124
+
125
+ <body class="nav-sidebar floating">
126
+
127
+ <div id="quarto-search-results"></div>
128
+ <header id="quarto-header" class="headroom fixed-top">
129
+ <nav class="quarto-secondary-nav">
130
+ <div class="container-fluid d-flex">
131
+ <button type="button" class="quarto-btn-toggle btn" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
132
+ <i class="bi bi-layout-text-sidebar-reverse"></i>
133
+ </button>
134
+ <nav class="quarto-page-breadcrumbs" aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="./cw012square_sum.html"><span class="chapter-number">12</span>&nbsp; <span class="chapter-title">Square(n) Sum</span></a></li></ol></nav>
135
+ <a class="flex-grow-1" role="button" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
136
+ </a>
137
+ <button type="button" class="btn quarto-search-button" aria-label="" onclick="window.quartoOpenSearch();">
138
+ <i class="bi bi-search"></i>
139
+ </button>
140
+ </div>
141
+ </nav>
142
+ </header>
143
+ <!-- content -->
144
+ <div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article">
145
+ <!-- sidebar -->
146
+ <nav id="quarto-sidebar" class="sidebar collapse collapse-horizontal sidebar-navigation floating overflow-auto">
147
+ <div class="pt-lg-2 mt-2 text-left sidebar-header">
148
+ <div class="sidebar-title mb-0 py-0">
149
+ <a href="./">Codewars Challenge 2024 Menggunakan R dan RStudio</a>
150
+ <div class="sidebar-tools-main">
151
+ <a href="https://huggingface.co/spaces/aephidayatuloh/codewars2024/tree/main" rel="" title="Source Code" class="quarto-navigation-tool px-1" aria-label="Source Code"><i class="bi bi-git"></i></a>
152
+ </div>
153
+ </div>
154
+ </div>
155
+ <div class="mt-2 flex-shrink-0 align-items-center">
156
+ <div class="sidebar-search">
157
+ <div id="quarto-search" class="" title="Search"></div>
158
+ </div>
159
+ </div>
160
+ <div class="sidebar-menu-container">
161
+ <ul class="list-unstyled mt-1">
162
+ <li class="sidebar-item">
163
+ <div class="sidebar-item-container">
164
+ <a href="./index.html" class="sidebar-item-text sidebar-link">
165
+ <span class="menu-text">Pengantar</span></a>
166
+ </div>
167
+ </li>
168
+ <li class="sidebar-item">
169
+ <div class="sidebar-item-container">
170
+ <a href="./cw001evenodd.html" class="sidebar-item-text sidebar-link">
171
+ <span class="menu-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Even or Odd</span></span></a>
172
+ </div>
173
+ </li>
174
+ <li class="sidebar-item">
175
+ <div class="sidebar-item-container">
176
+ <a href="./cw002multiply.html" class="sidebar-item-text sidebar-link">
177
+ <span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Multiply</span></span></a>
178
+ </div>
179
+ </li>
180
+ <li class="sidebar-item">
181
+ <div class="sidebar-item-container">
182
+ <a href="./cw003countsheep.html" class="sidebar-item-text sidebar-link">
183
+ <span class="menu-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">If you can’t sleep, just count sheep!!</span></span></a>
184
+ </div>
185
+ </li>
186
+ <li class="sidebar-item">
187
+ <div class="sidebar-item-container">
188
+ <a href="./cw004reducegrow.html" class="sidebar-item-text sidebar-link">
189
+ <span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Beginner - Reduce but Grow</span></span></a>
190
+ </div>
191
+ </li>
192
+ <li class="sidebar-item">
193
+ <div class="sidebar-item-container">
194
+ <a href="./cw005make_negative.html" class="sidebar-item-text sidebar-link">
195
+ <span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Return Negative</span></span></a>
196
+ </div>
197
+ </li>
198
+ <li class="sidebar-item">
199
+ <div class="sidebar-item-container">
200
+ <a href="./cw006positive_sum.html" class="sidebar-item-text sidebar-link">
201
+ <span class="menu-text"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Sum of positive</span></span></a>
202
+ </div>
203
+ </li>
204
+ <li class="sidebar-item">
205
+ <div class="sidebar-item-container">
206
+ <a href="./cw007reversedstrings.html" class="sidebar-item-text sidebar-link">
207
+ <span class="menu-text"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Reversed Strings</span></span></a>
208
+ </div>
209
+ </li>
210
+ <li class="sidebar-item">
211
+ <div class="sidebar-item-container">
212
+ <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
213
+ <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
214
+ </div>
215
+ </li>
216
+ <li class="sidebar-item">
217
+ <div class="sidebar-item-container">
218
+ <a href="./cw009number_to_string.html" class="sidebar-item-text sidebar-link">
219
+ <span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span></a>
220
+ </div>
221
+ </li>
222
+ <li class="sidebar-item">
223
+ <div class="sidebar-item-container">
224
+ <a href="./cw010opposite.html" class="sidebar-item-text sidebar-link">
225
+ <span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span></a>
226
+ </div>
227
+ </li>
228
+ <li class="sidebar-item">
229
+ <div class="sidebar-item-container">
230
+ <a href="./cw011removeChar.html" class="sidebar-item-text sidebar-link">
231
+ <span class="menu-text"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Remove First and Last Character</span></span></a>
232
+ </div>
233
+ </li>
234
+ <li class="sidebar-item">
235
+ <div class="sidebar-item-container">
236
+ <a href="./cw012square_sum.html" class="sidebar-item-text sidebar-link active">
237
+ <span class="menu-text"><span class="chapter-number">12</span>&nbsp; <span class="chapter-title">Square(n) Sum</span></span></a>
238
+ </div>
239
+ </li>
240
+ </ul>
241
+ </div>
242
+ </nav>
243
+ <div id="quarto-sidebar-glass" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass"></div>
244
+ <!-- margin-sidebar -->
245
+ <div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
246
+ <nav id="TOC" role="doc-toc" class="toc-active">
247
+ <h2 id="toc-title">Table of contents</h2>
248
+
249
+ <ul>
250
+ <li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">12.1</span> Instruction</a></li>
251
+ <li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">12.2</span> YouTube Video</a></li>
252
+ <li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">12.3</span> Solution Code</a></li>
253
+ <li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">12.4</span> Test</a></li>
254
+ <li><a href="#supported-by" id="toc-supported-by" class="nav-link" data-scroll-target="#supported-by"><span class="header-section-number">12.5</span> Supported by</a></li>
255
+ </ul>
256
+ </nav>
257
+ </div>
258
+ <!-- main -->
259
+ <main class="content" id="quarto-document-content">
260
+
261
+ <header id="title-block-header" class="quarto-title-block default">
262
+ <div class="quarto-title">
263
+ <h1 class="title"><span class="chapter-number">12</span>&nbsp; <span class="chapter-title">Square(n) Sum</span></h1>
264
+ </div>
265
+
266
+
267
+
268
+ <div class="quarto-title-meta">
269
+
270
+
271
+
272
+
273
+ </div>
274
+
275
+
276
+ </header>
277
+
278
+ <p><span class="badge rounded-pill quarto-badge " style="background-color: grey;">8kyu</span> Tantangan #12/366 - 26 Feb 2024</p>
279
+ <p><a href="https://www.codewars.com/kata/515e271a311df0350d00000f/train/r" class="uri">https://www.codewars.com/kata/515e271a311df0350d00000f/train/r</a></p>
280
+ <section id="instruction" class="level2" data-number="12.1">
281
+ <h2 data-number="12.1" class="anchored" data-anchor-id="instruction"><span class="header-section-number">12.1</span> Instruction</h2>
282
+ <p>Complete the square sum function so that it squares each number passed into it and then sums the results together.</p>
283
+ <p>For example, for [1, 2, 2] it should return 9 because <span class="math inline">1^2+2^2+2^2=9</span>.</p>
284
+ </section>
285
+ <section id="youtube-video" class="level2" data-number="12.2">
286
+ <h2 data-number="12.2" class="anchored" data-anchor-id="youtube-video"><span class="header-section-number">12.2</span> YouTube Video</h2>
287
+ <div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/L8aczEhqymk?si=DSx84acpNvbkucrK" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
288
+ </section>
289
+ <section id="solution-code" class="level2" data-number="12.3">
290
+ <h2 data-number="12.3" class="anchored" data-anchor-id="solution-code"><span class="header-section-number">12.3</span> Solution Code</h2>
291
+ <div class="cell">
292
+ <div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>square_sum <span class="ot">&lt;-</span> <span class="cf">function</span>(nums) {</span>
293
+ <span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> (i <span class="cf">in</span> nums) {</span>
294
+ <span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> nums[i] <span class="ot">&lt;-</span> nums[i]<span class="sc">^</span><span class="dv">2</span></span>
295
+ <span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> }</span>
296
+ <span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">sum</span>(nums, <span class="at">na.rm =</span> <span class="cn">TRUE</span>)</span>
297
+ <span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
298
+ </div>
299
+ <div class="cell">
300
+ <div class="sourceCode cell-code" id="cb2"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>square_sum <span class="ot">&lt;-</span> <span class="cf">function</span>(nums) {</span>
301
+ <span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">sum</span>(nums<span class="sc">^</span><span class="dv">2</span>)</span>
302
+ <span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
303
+ </div>
304
+ </section>
305
+ <section id="test" class="level2" data-number="12.4">
306
+ <h2 data-number="12.4" class="anchored" data-anchor-id="test"><span class="header-section-number">12.4</span> Test</h2>
307
+ <div class="cell">
308
+ <div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(testthat)</span>
309
+ <span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
310
+ <span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">"basic tests"</span>, {</span>
311
+ <span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">square_sum</span>(<span class="fu">c</span>(<span class="dv">1</span>, <span class="dv">2</span>)), <span class="dv">5</span>)</span>
312
+ <span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">square_sum</span>(<span class="fu">c</span>(<span class="dv">0</span>, <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">5</span>)), <span class="dv">50</span>)</span>
313
+ <span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">square_sum</span>(<span class="fu">c</span>()), <span class="dv">0</span>)</span>
314
+ <span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">square_sum</span>(<span class="fu">c</span>(<span class="sc">-</span><span class="dv">1</span>, <span class="sc">-</span><span class="dv">2</span>)), <span class="dv">5</span>)</span>
315
+ <span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">square_sum</span>(<span class="fu">c</span>(<span class="sc">-</span><span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">1</span>)), <span class="dv">2</span>)</span>
316
+ <span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a>})</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
317
+ <div class="cell-output cell-output-stdout">
318
+ <pre><code>Test passed 🥇</code></pre>
319
+ </div>
320
+ </div>
321
+ </section>
322
+ <section id="supported-by" class="level2" data-number="12.5">
323
+ <h2 data-number="12.5" class="anchored" data-anchor-id="supported-by"><span class="header-section-number">12.5</span> Supported by</h2>
324
+ <div class="quarto-figure quarto-figure-center">
325
+ <figure class="figure">
326
+ <p><a href="https://www.starcore.co"><img src="new_starcore_logo.png" class="img-fluid figure-img"></a></p>
327
+ <figcaption class="figure-caption">StarCore Analytics</figcaption>
328
+ </figure>
329
+ </div>
330
+
331
+
332
+ </section>
333
+
334
+ </main> <!-- /main -->
335
+ <script id="quarto-html-after-body" type="application/javascript">
336
+ window.document.addEventListener("DOMContentLoaded", function (event) {
337
+ const toggleBodyColorMode = (bsSheetEl) => {
338
+ const mode = bsSheetEl.getAttribute("data-mode");
339
+ const bodyEl = window.document.querySelector("body");
340
+ if (mode === "dark") {
341
+ bodyEl.classList.add("quarto-dark");
342
+ bodyEl.classList.remove("quarto-light");
343
+ } else {
344
+ bodyEl.classList.add("quarto-light");
345
+ bodyEl.classList.remove("quarto-dark");
346
+ }
347
+ }
348
+ const toggleBodyColorPrimary = () => {
349
+ const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
350
+ if (bsSheetEl) {
351
+ toggleBodyColorMode(bsSheetEl);
352
+ }
353
+ }
354
+ toggleBodyColorPrimary();
355
+ const icon = "";
356
+ const anchorJS = new window.AnchorJS();
357
+ anchorJS.options = {
358
+ placement: 'right',
359
+ icon: icon
360
+ };
361
+ anchorJS.add('.anchored');
362
+ const isCodeAnnotation = (el) => {
363
+ for (const clz of el.classList) {
364
+ if (clz.startsWith('code-annotation-')) {
365
+ return true;
366
+ }
367
+ }
368
+ return false;
369
+ }
370
+ const clipboard = new window.ClipboardJS('.code-copy-button', {
371
+ text: function(trigger) {
372
+ const codeEl = trigger.previousElementSibling.cloneNode(true);
373
+ for (const childEl of codeEl.children) {
374
+ if (isCodeAnnotation(childEl)) {
375
+ childEl.remove();
376
+ }
377
+ }
378
+ return codeEl.innerText;
379
+ }
380
+ });
381
+ clipboard.on('success', function(e) {
382
+ // button target
383
+ const button = e.trigger;
384
+ // don't keep focus
385
+ button.blur();
386
+ // flash "checked"
387
+ button.classList.add('code-copy-button-checked');
388
+ var currentTitle = button.getAttribute("title");
389
+ button.setAttribute("title", "Copied!");
390
+ let tooltip;
391
+ if (window.bootstrap) {
392
+ button.setAttribute("data-bs-toggle", "tooltip");
393
+ button.setAttribute("data-bs-placement", "left");
394
+ button.setAttribute("data-bs-title", "Copied!");
395
+ tooltip = new bootstrap.Tooltip(button,
396
+ { trigger: "manual",
397
+ customClass: "code-copy-button-tooltip",
398
+ offset: [0, -8]});
399
+ tooltip.show();
400
+ }
401
+ setTimeout(function() {
402
+ if (tooltip) {
403
+ tooltip.hide();
404
+ button.removeAttribute("data-bs-title");
405
+ button.removeAttribute("data-bs-toggle");
406
+ button.removeAttribute("data-bs-placement");
407
+ }
408
+ button.setAttribute("title", currentTitle);
409
+ button.classList.remove('code-copy-button-checked');
410
+ }, 1000);
411
+ // clear code selection
412
+ e.clearSelection();
413
+ });
414
+ function tippyHover(el, contentFn) {
415
+ const config = {
416
+ allowHTML: true,
417
+ content: contentFn,
418
+ maxWidth: 500,
419
+ delay: 100,
420
+ arrow: false,
421
+ appendTo: function(el) {
422
+ return el.parentElement;
423
+ },
424
+ interactive: true,
425
+ interactiveBorder: 10,
426
+ theme: 'quarto',
427
+ placement: 'bottom-start'
428
+ };
429
+ window.tippy(el, config);
430
+ }
431
+ const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
432
+ for (var i=0; i<noterefs.length; i++) {
433
+ const ref = noterefs[i];
434
+ tippyHover(ref, function() {
435
+ // use id or data attribute instead here
436
+ let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
437
+ try { href = new URL(href).hash; } catch {}
438
+ const id = href.replace(/^#\/?/, "");
439
+ const note = window.document.getElementById(id);
440
+ return note.innerHTML;
441
+ });
442
+ }
443
+ let selectedAnnoteEl;
444
+ const selectorForAnnotation = ( cell, annotation) => {
445
+ let cellAttr = 'data-code-cell="' + cell + '"';
446
+ let lineAttr = 'data-code-annotation="' + annotation + '"';
447
+ const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
448
+ return selector;
449
+ }
450
+ const selectCodeLines = (annoteEl) => {
451
+ const doc = window.document;
452
+ const targetCell = annoteEl.getAttribute("data-target-cell");
453
+ const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
454
+ const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
455
+ const lines = annoteSpan.getAttribute("data-code-lines").split(",");
456
+ const lineIds = lines.map((line) => {
457
+ return targetCell + "-" + line;
458
+ })
459
+ let top = null;
460
+ let height = null;
461
+ let parent = null;
462
+ if (lineIds.length > 0) {
463
+ //compute the position of the single el (top and bottom and make a div)
464
+ const el = window.document.getElementById(lineIds[0]);
465
+ top = el.offsetTop;
466
+ height = el.offsetHeight;
467
+ parent = el.parentElement.parentElement;
468
+ if (lineIds.length > 1) {
469
+ const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
470
+ const bottom = lastEl.offsetTop + lastEl.offsetHeight;
471
+ height = bottom - top;
472
+ }
473
+ if (top !== null && height !== null && parent !== null) {
474
+ // cook up a div (if necessary) and position it
475
+ let div = window.document.getElementById("code-annotation-line-highlight");
476
+ if (div === null) {
477
+ div = window.document.createElement("div");
478
+ div.setAttribute("id", "code-annotation-line-highlight");
479
+ div.style.position = 'absolute';
480
+ parent.appendChild(div);
481
+ }
482
+ div.style.top = top - 2 + "px";
483
+ div.style.height = height + 4 + "px";
484
+ let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
485
+ if (gutterDiv === null) {
486
+ gutterDiv = window.document.createElement("div");
487
+ gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
488
+ gutterDiv.style.position = 'absolute';
489
+ const codeCell = window.document.getElementById(targetCell);
490
+ const gutter = codeCell.querySelector('.code-annotation-gutter');
491
+ gutter.appendChild(gutterDiv);
492
+ }
493
+ gutterDiv.style.top = top - 2 + "px";
494
+ gutterDiv.style.height = height + 4 + "px";
495
+ }
496
+ selectedAnnoteEl = annoteEl;
497
+ }
498
+ };
499
+ const unselectCodeLines = () => {
500
+ const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
501
+ elementsIds.forEach((elId) => {
502
+ const div = window.document.getElementById(elId);
503
+ if (div) {
504
+ div.remove();
505
+ }
506
+ });
507
+ selectedAnnoteEl = undefined;
508
+ };
509
+ // Attach click handler to the DT
510
+ const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
511
+ for (const annoteDlNode of annoteDls) {
512
+ annoteDlNode.addEventListener('click', (event) => {
513
+ const clickedEl = event.target;
514
+ if (clickedEl !== selectedAnnoteEl) {
515
+ unselectCodeLines();
516
+ const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
517
+ if (activeEl) {
518
+ activeEl.classList.remove('code-annotation-active');
519
+ }
520
+ selectCodeLines(clickedEl);
521
+ clickedEl.classList.add('code-annotation-active');
522
+ } else {
523
+ // Unselect the line
524
+ unselectCodeLines();
525
+ clickedEl.classList.remove('code-annotation-active');
526
+ }
527
+ });
528
+ }
529
+ const findCites = (el) => {
530
+ const parentEl = el.parentElement;
531
+ if (parentEl) {
532
+ const cites = parentEl.dataset.cites;
533
+ if (cites) {
534
+ return {
535
+ el,
536
+ cites: cites.split(' ')
537
+ };
538
+ } else {
539
+ return findCites(el.parentElement)
540
+ }
541
+ } else {
542
+ return undefined;
543
+ }
544
+ };
545
+ var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
546
+ for (var i=0; i<bibliorefs.length; i++) {
547
+ const ref = bibliorefs[i];
548
+ const citeInfo = findCites(ref);
549
+ if (citeInfo) {
550
+ tippyHover(citeInfo.el, function() {
551
+ var popup = window.document.createElement('div');
552
+ citeInfo.cites.forEach(function(cite) {
553
+ var citeDiv = window.document.createElement('div');
554
+ citeDiv.classList.add('hanging-indent');
555
+ citeDiv.classList.add('csl-entry');
556
+ var biblioDiv = window.document.getElementById('ref-' + cite);
557
+ if (biblioDiv) {
558
+ citeDiv.innerHTML = biblioDiv.innerHTML;
559
+ }
560
+ popup.appendChild(citeDiv);
561
+ });
562
+ return popup.innerHTML;
563
+ });
564
+ }
565
+ }
566
+ });
567
+ </script>
568
+ <nav class="page-navigation">
569
+ <div class="nav-page nav-page-previous">
570
+ <a href="./cw011removeChar.html" class="pagination-link">
571
+ <i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Remove First and Last Character</span></span>
572
+ </a>
573
+ </div>
574
+ <div class="nav-page nav-page-next">
575
+ </div>
576
+ </nav>
577
+ </div> <!-- /content -->
578
+
579
+
580
+
581
+ </body></html>
index.html CHANGED
@@ -162,6 +162,30 @@ ul.task-list li input[type="checkbox"] {
162
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
163
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
164
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  </li>
166
  </ul>
167
  </div>
 
162
  <a href="./cw008bool_to_word.html" class="sidebar-item-text sidebar-link">
163
  <span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">Convert boolean values to strings ‘Yes’ or ‘No’</span></span></a>
164
  </div>
165
+ </li>
166
+ <li class="sidebar-item">
167
+ <div class="sidebar-item-container">
168
+ <a href="./cw009number_to_string.html" class="sidebar-item-text sidebar-link">
169
+ <span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Convert a Number to a String!</span></span></a>
170
+ </div>
171
+ </li>
172
+ <li class="sidebar-item">
173
+ <div class="sidebar-item-container">
174
+ <a href="./cw010opposite.html" class="sidebar-item-text sidebar-link">
175
+ <span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Opposite number</span></span></a>
176
+ </div>
177
+ </li>
178
+ <li class="sidebar-item">
179
+ <div class="sidebar-item-container">
180
+ <a href="./cw011removeChar.html" class="sidebar-item-text sidebar-link">
181
+ <span class="menu-text"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Remove First and Last Character</span></span></a>
182
+ </div>
183
+ </li>
184
+ <li class="sidebar-item">
185
+ <div class="sidebar-item-container">
186
+ <a href="./cw012square_sum.html" class="sidebar-item-text sidebar-link">
187
+ <span class="menu-text"><span class="chapter-number">12</span>&nbsp; <span class="chapter-title">Square(n) Sum</span></span></a>
188
+ </div>
189
  </li>
190
  </ul>
191
  </div>