Spaces:
Running
Running
aepstar
commited on
Commit
·
cc5e003
1
Parent(s):
4aa3888
update
Browse files- _quarto.yml +12 -8
- cw001evenodd.html +561 -0
- cw002multiply.html +542 -0
- cw003countsheep.html +545 -0
- cw004reducegrow.html +539 -0
- cw005make_negative.html +542 -0
- cw006positive_sum.html +552 -0
- index.html +18 -8
_quarto.yml
CHANGED
@@ -6,18 +6,22 @@ book:
|
|
6 |
author: "Aep Hidayatuloh"
|
7 |
date: last-modified
|
8 |
date-format: "[Last Updated on ] DD MMMM, YYYY"
|
|
|
|
|
|
|
|
|
|
|
9 |
chapters:
|
10 |
- index.qmd
|
11 |
-
-
|
12 |
-
-
|
13 |
-
-
|
14 |
-
-
|
15 |
-
-
|
16 |
-
-
|
17 |
-
- references.qmd
|
18 |
|
19 |
bibliography: references.bib
|
20 |
-
|
21 |
format:
|
22 |
html:
|
23 |
theme: cosmo
|
|
|
6 |
author: "Aep Hidayatuloh"
|
7 |
date: last-modified
|
8 |
date-format: "[Last Updated on ] DD MMMM, YYYY"
|
9 |
+
favicon: logo.png
|
10 |
+
twitter-card: true
|
11 |
+
site-url: https://huggingface.co/spaces/aephidayatuloh/codewars2024/
|
12 |
+
search: true
|
13 |
+
repo-url: https://huggingface.co/spaces/aephidayatuloh/codewars2024/tree/main
|
14 |
chapters:
|
15 |
- index.qmd
|
16 |
+
- cw001evenodd.qmd
|
17 |
+
- cw002multiply.qmd
|
18 |
+
- cw003countsheep.qmd
|
19 |
+
- cw004reducegrow.qmd
|
20 |
+
- cw005make_negative.qmd
|
21 |
+
- cw006positive_sum.qmd
|
|
|
22 |
|
23 |
bibliography: references.bib
|
24 |
+
|
25 |
format:
|
26 |
html:
|
27 |
theme: cosmo
|
cw001evenodd.html
ADDED
@@ -0,0 +1,561 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 - 1 Even or Odd</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="./cw002multiply.html" rel="next">
|
68 |
+
<link href="./index.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 - 1 Even or Odd">
|
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="./cw001evenodd.html"><span class="chapter-number">1</span> <span class="chapter-title">Even or Odd</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 active">
|
156 |
+
<span class="menu-text"><span class="chapter-number">1</span> <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> <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> <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> <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> <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> <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="./references.html" class="sidebar-item-text sidebar-link">
|
192 |
+
<span class="menu-text">References</span></a>
|
193 |
+
</div>
|
194 |
+
</li>
|
195 |
+
</ul>
|
196 |
+
</div>
|
197 |
+
</nav>
|
198 |
+
<div id="quarto-sidebar-glass" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass"></div>
|
199 |
+
<!-- margin-sidebar -->
|
200 |
+
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
|
201 |
+
<nav id="TOC" role="doc-toc" class="toc-active">
|
202 |
+
<h2 id="toc-title">Table of contents</h2>
|
203 |
+
|
204 |
+
<ul>
|
205 |
+
<li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">1.1</span> Instruction</a></li>
|
206 |
+
<li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">1.2</span> YouTube Video</a></li>
|
207 |
+
<li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">1.3</span> Solution Code</a></li>
|
208 |
+
<li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">1.4</span> Test</a></li>
|
209 |
+
<li><a href="#supported-by" id="toc-supported-by" class="nav-link" data-scroll-target="#supported-by"><span class="header-section-number">1.5</span> Supported by</a></li>
|
210 |
+
</ul>
|
211 |
+
</nav>
|
212 |
+
</div>
|
213 |
+
<!-- main -->
|
214 |
+
<main class="content" id="quarto-document-content">
|
215 |
+
|
216 |
+
<header id="title-block-header" class="quarto-title-block default">
|
217 |
+
<div class="quarto-title">
|
218 |
+
<h1 class="title"><span id="evenodd" class="quarto-section-identifier"><span class="chapter-number">1</span> <span class="chapter-title">Even or Odd</span></span></h1>
|
219 |
+
</div>
|
220 |
+
|
221 |
+
|
222 |
+
|
223 |
+
<div class="quarto-title-meta">
|
224 |
+
|
225 |
+
|
226 |
+
|
227 |
+
|
228 |
+
</div>
|
229 |
+
|
230 |
+
|
231 |
+
</header>
|
232 |
+
|
233 |
+
<p>Tantangan #1/366 - 15 Feb 2024</p>
|
234 |
+
<p><a href="https://www.codewars.com/kata/53da3dbb4a5168369a0000fe/train/r" class="uri">https://www.codewars.com/kata/53da3dbb4a5168369a0000fe/train/r</a></p>
|
235 |
+
<p><span class="badge rounded-pill quarto-badge " style="background-color: grey;">8kyu</span> Even or Odd</p>
|
236 |
+
<section id="instruction" class="level2" data-number="1.1">
|
237 |
+
<h2 data-number="1.1" class="anchored" data-anchor-id="instruction"><span class="header-section-number">1.1</span> Instruction</h2>
|
238 |
+
<p>Create a function that takes an integer as an argument and returns <code>"Even"</code> for even numbers or <code>"Odd"</code> for odd numbers.</p>
|
239 |
+
</section>
|
240 |
+
<section id="youtube-video" class="level2" data-number="1.2">
|
241 |
+
<h2 data-number="1.2" class="anchored" data-anchor-id="youtube-video"><span class="header-section-number">1.2</span> YouTube Video</h2>
|
242 |
+
<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>
|
243 |
+
</section>
|
244 |
+
<section id="solution-code" class="level2" data-number="1.3">
|
245 |
+
<h2 data-number="1.3" class="anchored" data-anchor-id="solution-code"><span class="header-section-number">1.3</span> Solution Code</h2>
|
246 |
+
<p>Solusi bar-bar</p>
|
247 |
+
<div class="cell">
|
248 |
+
<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>even_or_odd <span class="ot"><-</span> <span class="cf">function</span>(n) {</span>
|
249 |
+
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">ifelse</span>(<span class="fu">abs</span>(n<span class="sc">/</span><span class="dv">2</span> <span class="sc">-</span> <span class="fu">as.integer</span>(n<span class="sc">/</span><span class="dv">2</span>)) <span class="sc">==</span> <span class="fl">0.5</span>, <span class="st">"Odd"</span>, <span class="st">"Even"</span>)</span>
|
250 |
+
<span id="cb1-3"><a href="#cb1-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>
|
251 |
+
</div>
|
252 |
+
<p>Solusi simple</p>
|
253 |
+
<div class="cell">
|
254 |
+
<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>even_or_odd <span class="ot"><-</span> <span class="cf">function</span>(n) {</span>
|
255 |
+
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="co"># %% operator modulo</span></span>
|
256 |
+
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">ifelse</span>(n <span class="sc">%%</span> <span class="dv">2</span> <span class="sc">==</span> <span class="dv">1</span>, <span class="st">"Odd"</span>, <span class="st">"Even"</span>)</span>
|
257 |
+
<span id="cb2-4"><a href="#cb2-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>
|
258 |
+
</div>
|
259 |
+
<div class="cell">
|
260 |
+
<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>even_or_odd <span class="ot"><-</span> <span class="cf">function</span>(n) <span class="fu">c</span>(<span class="st">"Even"</span>, <span class="st">"Odd"</span>)[n <span class="sc">%%</span> <span class="dv">2</span> <span class="sc">+</span> <span class="dv">1</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
261 |
+
</div>
|
262 |
+
</section>
|
263 |
+
<section id="test" class="level2" data-number="1.4">
|
264 |
+
<h2 data-number="1.4" class="anchored" data-anchor-id="test"><span class="header-section-number">1.4</span> Test</h2>
|
265 |
+
<div class="cell">
|
266 |
+
<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>
|
267 |
+
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">'even_or_odd(1) returns "Odd"'</span>, {</span>
|
268 |
+
<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>
|
269 |
+
<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>
|
270 |
+
<div class="cell-output cell-output-stdout">
|
271 |
+
<pre><code>Test passed 🥳</code></pre>
|
272 |
+
</div>
|
273 |
+
<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>
|
274 |
+
<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>
|
275 |
+
<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>
|
276 |
+
<div class="cell-output cell-output-stdout">
|
277 |
+
<pre><code>Test passed 🎉</code></pre>
|
278 |
+
</div>
|
279 |
+
<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>
|
280 |
+
<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>
|
281 |
+
<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>
|
282 |
+
<div class="cell-output cell-output-stdout">
|
283 |
+
<pre><code>Test passed 😸</code></pre>
|
284 |
+
</div>
|
285 |
+
<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>
|
286 |
+
<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>
|
287 |
+
<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>
|
288 |
+
<div class="cell-output cell-output-stdout">
|
289 |
+
<pre><code>Test passed 🥇</code></pre>
|
290 |
+
</div>
|
291 |
+
<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>
|
292 |
+
<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>
|
293 |
+
<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>
|
294 |
+
<div class="cell-output cell-output-stdout">
|
295 |
+
<pre><code>Test passed 🥳</code></pre>
|
296 |
+
</div>
|
297 |
+
</div>
|
298 |
+
</section>
|
299 |
+
<section id="supported-by" class="level2" data-number="1.5">
|
300 |
+
<h2 data-number="1.5" class="anchored" data-anchor-id="supported-by"><span class="header-section-number">1.5</span> Supported by</h2>
|
301 |
+
<div class="quarto-figure quarto-figure-center">
|
302 |
+
<figure class="figure">
|
303 |
+
<p><a href="https://www.starcore.co"><img src="new_starcore_logo.png" class="img-fluid figure-img"></a></p>
|
304 |
+
<figcaption class="figure-caption">StarCore Analytics</figcaption>
|
305 |
+
</figure>
|
306 |
+
</div>
|
307 |
+
|
308 |
+
|
309 |
+
</section>
|
310 |
+
|
311 |
+
</main> <!-- /main -->
|
312 |
+
<script id="quarto-html-after-body" type="application/javascript">
|
313 |
+
window.document.addEventListener("DOMContentLoaded", function (event) {
|
314 |
+
const toggleBodyColorMode = (bsSheetEl) => {
|
315 |
+
const mode = bsSheetEl.getAttribute("data-mode");
|
316 |
+
const bodyEl = window.document.querySelector("body");
|
317 |
+
if (mode === "dark") {
|
318 |
+
bodyEl.classList.add("quarto-dark");
|
319 |
+
bodyEl.classList.remove("quarto-light");
|
320 |
+
} else {
|
321 |
+
bodyEl.classList.add("quarto-light");
|
322 |
+
bodyEl.classList.remove("quarto-dark");
|
323 |
+
}
|
324 |
+
}
|
325 |
+
const toggleBodyColorPrimary = () => {
|
326 |
+
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
|
327 |
+
if (bsSheetEl) {
|
328 |
+
toggleBodyColorMode(bsSheetEl);
|
329 |
+
}
|
330 |
+
}
|
331 |
+
toggleBodyColorPrimary();
|
332 |
+
const icon = "";
|
333 |
+
const anchorJS = new window.AnchorJS();
|
334 |
+
anchorJS.options = {
|
335 |
+
placement: 'right',
|
336 |
+
icon: icon
|
337 |
+
};
|
338 |
+
anchorJS.add('.anchored');
|
339 |
+
const isCodeAnnotation = (el) => {
|
340 |
+
for (const clz of el.classList) {
|
341 |
+
if (clz.startsWith('code-annotation-')) {
|
342 |
+
return true;
|
343 |
+
}
|
344 |
+
}
|
345 |
+
return false;
|
346 |
+
}
|
347 |
+
const clipboard = new window.ClipboardJS('.code-copy-button', {
|
348 |
+
text: function(trigger) {
|
349 |
+
const codeEl = trigger.previousElementSibling.cloneNode(true);
|
350 |
+
for (const childEl of codeEl.children) {
|
351 |
+
if (isCodeAnnotation(childEl)) {
|
352 |
+
childEl.remove();
|
353 |
+
}
|
354 |
+
}
|
355 |
+
return codeEl.innerText;
|
356 |
+
}
|
357 |
+
});
|
358 |
+
clipboard.on('success', function(e) {
|
359 |
+
// button target
|
360 |
+
const button = e.trigger;
|
361 |
+
// don't keep focus
|
362 |
+
button.blur();
|
363 |
+
// flash "checked"
|
364 |
+
button.classList.add('code-copy-button-checked');
|
365 |
+
var currentTitle = button.getAttribute("title");
|
366 |
+
button.setAttribute("title", "Copied!");
|
367 |
+
let tooltip;
|
368 |
+
if (window.bootstrap) {
|
369 |
+
button.setAttribute("data-bs-toggle", "tooltip");
|
370 |
+
button.setAttribute("data-bs-placement", "left");
|
371 |
+
button.setAttribute("data-bs-title", "Copied!");
|
372 |
+
tooltip = new bootstrap.Tooltip(button,
|
373 |
+
{ trigger: "manual",
|
374 |
+
customClass: "code-copy-button-tooltip",
|
375 |
+
offset: [0, -8]});
|
376 |
+
tooltip.show();
|
377 |
+
}
|
378 |
+
setTimeout(function() {
|
379 |
+
if (tooltip) {
|
380 |
+
tooltip.hide();
|
381 |
+
button.removeAttribute("data-bs-title");
|
382 |
+
button.removeAttribute("data-bs-toggle");
|
383 |
+
button.removeAttribute("data-bs-placement");
|
384 |
+
}
|
385 |
+
button.setAttribute("title", currentTitle);
|
386 |
+
button.classList.remove('code-copy-button-checked');
|
387 |
+
}, 1000);
|
388 |
+
// clear code selection
|
389 |
+
e.clearSelection();
|
390 |
+
});
|
391 |
+
function tippyHover(el, contentFn) {
|
392 |
+
const config = {
|
393 |
+
allowHTML: true,
|
394 |
+
content: contentFn,
|
395 |
+
maxWidth: 500,
|
396 |
+
delay: 100,
|
397 |
+
arrow: false,
|
398 |
+
appendTo: function(el) {
|
399 |
+
return el.parentElement;
|
400 |
+
},
|
401 |
+
interactive: true,
|
402 |
+
interactiveBorder: 10,
|
403 |
+
theme: 'quarto',
|
404 |
+
placement: 'bottom-start'
|
405 |
+
};
|
406 |
+
window.tippy(el, config);
|
407 |
+
}
|
408 |
+
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
|
409 |
+
for (var i=0; i<noterefs.length; i++) {
|
410 |
+
const ref = noterefs[i];
|
411 |
+
tippyHover(ref, function() {
|
412 |
+
// use id or data attribute instead here
|
413 |
+
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
|
414 |
+
try { href = new URL(href).hash; } catch {}
|
415 |
+
const id = href.replace(/^#\/?/, "");
|
416 |
+
const note = window.document.getElementById(id);
|
417 |
+
return note.innerHTML;
|
418 |
+
});
|
419 |
+
}
|
420 |
+
let selectedAnnoteEl;
|
421 |
+
const selectorForAnnotation = ( cell, annotation) => {
|
422 |
+
let cellAttr = 'data-code-cell="' + cell + '"';
|
423 |
+
let lineAttr = 'data-code-annotation="' + annotation + '"';
|
424 |
+
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
|
425 |
+
return selector;
|
426 |
+
}
|
427 |
+
const selectCodeLines = (annoteEl) => {
|
428 |
+
const doc = window.document;
|
429 |
+
const targetCell = annoteEl.getAttribute("data-target-cell");
|
430 |
+
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
|
431 |
+
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
|
432 |
+
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
|
433 |
+
const lineIds = lines.map((line) => {
|
434 |
+
return targetCell + "-" + line;
|
435 |
+
})
|
436 |
+
let top = null;
|
437 |
+
let height = null;
|
438 |
+
let parent = null;
|
439 |
+
if (lineIds.length > 0) {
|
440 |
+
//compute the position of the single el (top and bottom and make a div)
|
441 |
+
const el = window.document.getElementById(lineIds[0]);
|
442 |
+
top = el.offsetTop;
|
443 |
+
height = el.offsetHeight;
|
444 |
+
parent = el.parentElement.parentElement;
|
445 |
+
if (lineIds.length > 1) {
|
446 |
+
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
|
447 |
+
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
|
448 |
+
height = bottom - top;
|
449 |
+
}
|
450 |
+
if (top !== null && height !== null && parent !== null) {
|
451 |
+
// cook up a div (if necessary) and position it
|
452 |
+
let div = window.document.getElementById("code-annotation-line-highlight");
|
453 |
+
if (div === null) {
|
454 |
+
div = window.document.createElement("div");
|
455 |
+
div.setAttribute("id", "code-annotation-line-highlight");
|
456 |
+
div.style.position = 'absolute';
|
457 |
+
parent.appendChild(div);
|
458 |
+
}
|
459 |
+
div.style.top = top - 2 + "px";
|
460 |
+
div.style.height = height + 4 + "px";
|
461 |
+
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
|
462 |
+
if (gutterDiv === null) {
|
463 |
+
gutterDiv = window.document.createElement("div");
|
464 |
+
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
|
465 |
+
gutterDiv.style.position = 'absolute';
|
466 |
+
const codeCell = window.document.getElementById(targetCell);
|
467 |
+
const gutter = codeCell.querySelector('.code-annotation-gutter');
|
468 |
+
gutter.appendChild(gutterDiv);
|
469 |
+
}
|
470 |
+
gutterDiv.style.top = top - 2 + "px";
|
471 |
+
gutterDiv.style.height = height + 4 + "px";
|
472 |
+
}
|
473 |
+
selectedAnnoteEl = annoteEl;
|
474 |
+
}
|
475 |
+
};
|
476 |
+
const unselectCodeLines = () => {
|
477 |
+
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
|
478 |
+
elementsIds.forEach((elId) => {
|
479 |
+
const div = window.document.getElementById(elId);
|
480 |
+
if (div) {
|
481 |
+
div.remove();
|
482 |
+
}
|
483 |
+
});
|
484 |
+
selectedAnnoteEl = undefined;
|
485 |
+
};
|
486 |
+
// Attach click handler to the DT
|
487 |
+
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
|
488 |
+
for (const annoteDlNode of annoteDls) {
|
489 |
+
annoteDlNode.addEventListener('click', (event) => {
|
490 |
+
const clickedEl = event.target;
|
491 |
+
if (clickedEl !== selectedAnnoteEl) {
|
492 |
+
unselectCodeLines();
|
493 |
+
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
|
494 |
+
if (activeEl) {
|
495 |
+
activeEl.classList.remove('code-annotation-active');
|
496 |
+
}
|
497 |
+
selectCodeLines(clickedEl);
|
498 |
+
clickedEl.classList.add('code-annotation-active');
|
499 |
+
} else {
|
500 |
+
// Unselect the line
|
501 |
+
unselectCodeLines();
|
502 |
+
clickedEl.classList.remove('code-annotation-active');
|
503 |
+
}
|
504 |
+
});
|
505 |
+
}
|
506 |
+
const findCites = (el) => {
|
507 |
+
const parentEl = el.parentElement;
|
508 |
+
if (parentEl) {
|
509 |
+
const cites = parentEl.dataset.cites;
|
510 |
+
if (cites) {
|
511 |
+
return {
|
512 |
+
el,
|
513 |
+
cites: cites.split(' ')
|
514 |
+
};
|
515 |
+
} else {
|
516 |
+
return findCites(el.parentElement)
|
517 |
+
}
|
518 |
+
} else {
|
519 |
+
return undefined;
|
520 |
+
}
|
521 |
+
};
|
522 |
+
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
|
523 |
+
for (var i=0; i<bibliorefs.length; i++) {
|
524 |
+
const ref = bibliorefs[i];
|
525 |
+
const citeInfo = findCites(ref);
|
526 |
+
if (citeInfo) {
|
527 |
+
tippyHover(citeInfo.el, function() {
|
528 |
+
var popup = window.document.createElement('div');
|
529 |
+
citeInfo.cites.forEach(function(cite) {
|
530 |
+
var citeDiv = window.document.createElement('div');
|
531 |
+
citeDiv.classList.add('hanging-indent');
|
532 |
+
citeDiv.classList.add('csl-entry');
|
533 |
+
var biblioDiv = window.document.getElementById('ref-' + cite);
|
534 |
+
if (biblioDiv) {
|
535 |
+
citeDiv.innerHTML = biblioDiv.innerHTML;
|
536 |
+
}
|
537 |
+
popup.appendChild(citeDiv);
|
538 |
+
});
|
539 |
+
return popup.innerHTML;
|
540 |
+
});
|
541 |
+
}
|
542 |
+
}
|
543 |
+
});
|
544 |
+
</script>
|
545 |
+
<nav class="page-navigation">
|
546 |
+
<div class="nav-page nav-page-previous">
|
547 |
+
<a href="./index.html" class="pagination-link">
|
548 |
+
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text">Pengantar</span>
|
549 |
+
</a>
|
550 |
+
</div>
|
551 |
+
<div class="nav-page nav-page-next">
|
552 |
+
<a href="./cw002multiply.html" class="pagination-link">
|
553 |
+
<span class="nav-page-text"><span class="chapter-number">2</span> <span class="chapter-title">Multiply</span></span> <i class="bi bi-arrow-right-short"></i>
|
554 |
+
</a>
|
555 |
+
</div>
|
556 |
+
</nav>
|
557 |
+
</div> <!-- /content -->
|
558 |
+
|
559 |
+
|
560 |
+
|
561 |
+
</body></html>
|
cw002multiply.html
ADDED
@@ -0,0 +1,542 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 - 2 Multiply</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="./cw003countsheep.html" rel="next">
|
68 |
+
<link href="./cw001evenodd.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 - 2 Multiply">
|
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="./cw002multiply.html"><span class="chapter-number">2</span> <span class="chapter-title">Multiply</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> <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 active">
|
162 |
+
<span class="menu-text"><span class="chapter-number">2</span> <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> <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> <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> <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> <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="./references.html" class="sidebar-item-text sidebar-link">
|
192 |
+
<span class="menu-text">References</span></a>
|
193 |
+
</div>
|
194 |
+
</li>
|
195 |
+
</ul>
|
196 |
+
</div>
|
197 |
+
</nav>
|
198 |
+
<div id="quarto-sidebar-glass" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass"></div>
|
199 |
+
<!-- margin-sidebar -->
|
200 |
+
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
|
201 |
+
<nav id="TOC" role="doc-toc" class="toc-active">
|
202 |
+
<h2 id="toc-title">Table of contents</h2>
|
203 |
+
|
204 |
+
<ul>
|
205 |
+
<li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">2.1</span> Instruction</a></li>
|
206 |
+
<li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">2.2</span> YouTube Video</a></li>
|
207 |
+
<li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">2.3</span> Solution Code</a></li>
|
208 |
+
<li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">2.4</span> Test</a></li>
|
209 |
+
<li><a href="#supported-by" id="toc-supported-by" class="nav-link" data-scroll-target="#supported-by"><span class="header-section-number">2.5</span> Supported by</a></li>
|
210 |
+
</ul>
|
211 |
+
</nav>
|
212 |
+
</div>
|
213 |
+
<!-- main -->
|
214 |
+
<main class="content" id="quarto-document-content">
|
215 |
+
|
216 |
+
<header id="title-block-header" class="quarto-title-block default">
|
217 |
+
<div class="quarto-title">
|
218 |
+
<h1 class="title"><span id="multiply" class="quarto-section-identifier"><span class="chapter-number">2</span> <span class="chapter-title">Multiply</span></span></h1>
|
219 |
+
</div>
|
220 |
+
|
221 |
+
|
222 |
+
|
223 |
+
<div class="quarto-title-meta">
|
224 |
+
|
225 |
+
|
226 |
+
|
227 |
+
|
228 |
+
</div>
|
229 |
+
|
230 |
+
|
231 |
+
</header>
|
232 |
+
|
233 |
+
<p>Tantangan #2/366 - 16 Feb 2024</p>
|
234 |
+
<p><a href="https://www.codewars.com/kata/50654ddff44f800200000004/train/r" class="uri">https://www.codewars.com/kata/50654ddff44f800200000004/train/r</a></p>
|
235 |
+
<p><span class="badge rounded-pill quarto-badge " style="background-color: grey;">8kyu</span> Multiply</p>
|
236 |
+
<section id="instruction" class="level2" data-number="2.1">
|
237 |
+
<h2 data-number="2.1" class="anchored" data-anchor-id="instruction"><span class="header-section-number">2.1</span> Instruction</h2>
|
238 |
+
<p>This code does not execute properly. Try to figure out why.</p>
|
239 |
+
<pre><code>mul <- function(a, b) {
|
240 |
+
a * c # try to figure out why it doesn't work!
|
241 |
+
}</code></pre>
|
242 |
+
</section>
|
243 |
+
<section id="youtube-video" class="level2" data-number="2.2">
|
244 |
+
<h2 data-number="2.2" class="anchored" data-anchor-id="youtube-video"><span class="header-section-number">2.2</span> YouTube Video</h2>
|
245 |
+
<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>
|
246 |
+
</section>
|
247 |
+
<section id="solution-code" class="level2" data-number="2.3">
|
248 |
+
<h2 data-number="2.3" class="anchored" data-anchor-id="solution-code"><span class="header-section-number">2.3</span> Solution Code</h2>
|
249 |
+
<p>Karena argumen dari function <code>mul()</code> adalah <code>a</code> dan <code>b</code> sedangkan operasi perkalian di dalamnya menggunakan <code>c</code> yang belum diketahui dan tidak ada objek tersebut.</p>
|
250 |
+
<div class="cell">
|
251 |
+
<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>mul <span class="ot"><-</span> <span class="cf">function</span>(a, b) {</span>
|
252 |
+
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> a <span class="sc">*</span> c <span class="co"># try to figure out why it doesn't work!</span></span>
|
253 |
+
<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>
|
254 |
+
</div>
|
255 |
+
<p>Solusi: ganti objek <code>c</code> di dalam function <code>mul()</code> dengan <code>b</code> dari argumen function tersebut.</p>
|
256 |
+
<div class="cell">
|
257 |
+
<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>mul <span class="ot"><-</span> <span class="cf">function</span>(a, b) {</span>
|
258 |
+
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> a <span class="sc">*</span> b </span>
|
259 |
+
<span id="cb3-3"><a href="#cb3-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>
|
260 |
+
</div>
|
261 |
+
</section>
|
262 |
+
<section id="test" class="level2" data-number="2.4">
|
263 |
+
<h2 data-number="2.4" class="anchored" data-anchor-id="test"><span class="header-section-number">2.4</span> Test</h2>
|
264 |
+
<div class="cell">
|
265 |
+
<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>
|
266 |
+
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
|
267 |
+
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">"test for associativity of multiplication"</span>, {</span>
|
268 |
+
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> a <span class="ot"><-</span> <span class="fu">runif</span>(<span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">10000</span>)</span>
|
269 |
+
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> b <span class="ot"><-</span> <span class="fu">runif</span>(<span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">10000</span>)</span>
|
270 |
+
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a> c <span class="ot"><-</span> <span class="fu">runif</span>(<span class="dv">1</span>, <span class="dv">0</span>, <span class="dv">10000</span>)</span>
|
271 |
+
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">mul</span>(a, b), a <span class="sc">*</span> b)</span>
|
272 |
+
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">mul</span>(<span class="fu">mul</span>(a, b), c), a <span class="sc">*</span> b <span class="sc">*</span> c)</span>
|
273 |
+
<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>
|
274 |
+
<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>
|
275 |
+
<div class="cell-output cell-output-stdout">
|
276 |
+
<pre><code>Test passed 😀</code></pre>
|
277 |
+
</div>
|
278 |
+
</div>
|
279 |
+
</section>
|
280 |
+
<section id="supported-by" class="level2" data-number="2.5">
|
281 |
+
<h2 data-number="2.5" class="anchored" data-anchor-id="supported-by"><span class="header-section-number">2.5</span> Supported by</h2>
|
282 |
+
<div class="quarto-figure quarto-figure-center">
|
283 |
+
<figure class="figure">
|
284 |
+
<p><a href="https://www.starcore.co"><img src="new_starcore_logo.png" class="img-fluid figure-img"></a></p>
|
285 |
+
<figcaption class="figure-caption">StarCore Analytics</figcaption>
|
286 |
+
</figure>
|
287 |
+
</div>
|
288 |
+
|
289 |
+
|
290 |
+
</section>
|
291 |
+
|
292 |
+
</main> <!-- /main -->
|
293 |
+
<script id="quarto-html-after-body" type="application/javascript">
|
294 |
+
window.document.addEventListener("DOMContentLoaded", function (event) {
|
295 |
+
const toggleBodyColorMode = (bsSheetEl) => {
|
296 |
+
const mode = bsSheetEl.getAttribute("data-mode");
|
297 |
+
const bodyEl = window.document.querySelector("body");
|
298 |
+
if (mode === "dark") {
|
299 |
+
bodyEl.classList.add("quarto-dark");
|
300 |
+
bodyEl.classList.remove("quarto-light");
|
301 |
+
} else {
|
302 |
+
bodyEl.classList.add("quarto-light");
|
303 |
+
bodyEl.classList.remove("quarto-dark");
|
304 |
+
}
|
305 |
+
}
|
306 |
+
const toggleBodyColorPrimary = () => {
|
307 |
+
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
|
308 |
+
if (bsSheetEl) {
|
309 |
+
toggleBodyColorMode(bsSheetEl);
|
310 |
+
}
|
311 |
+
}
|
312 |
+
toggleBodyColorPrimary();
|
313 |
+
const icon = "";
|
314 |
+
const anchorJS = new window.AnchorJS();
|
315 |
+
anchorJS.options = {
|
316 |
+
placement: 'right',
|
317 |
+
icon: icon
|
318 |
+
};
|
319 |
+
anchorJS.add('.anchored');
|
320 |
+
const isCodeAnnotation = (el) => {
|
321 |
+
for (const clz of el.classList) {
|
322 |
+
if (clz.startsWith('code-annotation-')) {
|
323 |
+
return true;
|
324 |
+
}
|
325 |
+
}
|
326 |
+
return false;
|
327 |
+
}
|
328 |
+
const clipboard = new window.ClipboardJS('.code-copy-button', {
|
329 |
+
text: function(trigger) {
|
330 |
+
const codeEl = trigger.previousElementSibling.cloneNode(true);
|
331 |
+
for (const childEl of codeEl.children) {
|
332 |
+
if (isCodeAnnotation(childEl)) {
|
333 |
+
childEl.remove();
|
334 |
+
}
|
335 |
+
}
|
336 |
+
return codeEl.innerText;
|
337 |
+
}
|
338 |
+
});
|
339 |
+
clipboard.on('success', function(e) {
|
340 |
+
// button target
|
341 |
+
const button = e.trigger;
|
342 |
+
// don't keep focus
|
343 |
+
button.blur();
|
344 |
+
// flash "checked"
|
345 |
+
button.classList.add('code-copy-button-checked');
|
346 |
+
var currentTitle = button.getAttribute("title");
|
347 |
+
button.setAttribute("title", "Copied!");
|
348 |
+
let tooltip;
|
349 |
+
if (window.bootstrap) {
|
350 |
+
button.setAttribute("data-bs-toggle", "tooltip");
|
351 |
+
button.setAttribute("data-bs-placement", "left");
|
352 |
+
button.setAttribute("data-bs-title", "Copied!");
|
353 |
+
tooltip = new bootstrap.Tooltip(button,
|
354 |
+
{ trigger: "manual",
|
355 |
+
customClass: "code-copy-button-tooltip",
|
356 |
+
offset: [0, -8]});
|
357 |
+
tooltip.show();
|
358 |
+
}
|
359 |
+
setTimeout(function() {
|
360 |
+
if (tooltip) {
|
361 |
+
tooltip.hide();
|
362 |
+
button.removeAttribute("data-bs-title");
|
363 |
+
button.removeAttribute("data-bs-toggle");
|
364 |
+
button.removeAttribute("data-bs-placement");
|
365 |
+
}
|
366 |
+
button.setAttribute("title", currentTitle);
|
367 |
+
button.classList.remove('code-copy-button-checked');
|
368 |
+
}, 1000);
|
369 |
+
// clear code selection
|
370 |
+
e.clearSelection();
|
371 |
+
});
|
372 |
+
function tippyHover(el, contentFn) {
|
373 |
+
const config = {
|
374 |
+
allowHTML: true,
|
375 |
+
content: contentFn,
|
376 |
+
maxWidth: 500,
|
377 |
+
delay: 100,
|
378 |
+
arrow: false,
|
379 |
+
appendTo: function(el) {
|
380 |
+
return el.parentElement;
|
381 |
+
},
|
382 |
+
interactive: true,
|
383 |
+
interactiveBorder: 10,
|
384 |
+
theme: 'quarto',
|
385 |
+
placement: 'bottom-start'
|
386 |
+
};
|
387 |
+
window.tippy(el, config);
|
388 |
+
}
|
389 |
+
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
|
390 |
+
for (var i=0; i<noterefs.length; i++) {
|
391 |
+
const ref = noterefs[i];
|
392 |
+
tippyHover(ref, function() {
|
393 |
+
// use id or data attribute instead here
|
394 |
+
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
|
395 |
+
try { href = new URL(href).hash; } catch {}
|
396 |
+
const id = href.replace(/^#\/?/, "");
|
397 |
+
const note = window.document.getElementById(id);
|
398 |
+
return note.innerHTML;
|
399 |
+
});
|
400 |
+
}
|
401 |
+
let selectedAnnoteEl;
|
402 |
+
const selectorForAnnotation = ( cell, annotation) => {
|
403 |
+
let cellAttr = 'data-code-cell="' + cell + '"';
|
404 |
+
let lineAttr = 'data-code-annotation="' + annotation + '"';
|
405 |
+
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
|
406 |
+
return selector;
|
407 |
+
}
|
408 |
+
const selectCodeLines = (annoteEl) => {
|
409 |
+
const doc = window.document;
|
410 |
+
const targetCell = annoteEl.getAttribute("data-target-cell");
|
411 |
+
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
|
412 |
+
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
|
413 |
+
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
|
414 |
+
const lineIds = lines.map((line) => {
|
415 |
+
return targetCell + "-" + line;
|
416 |
+
})
|
417 |
+
let top = null;
|
418 |
+
let height = null;
|
419 |
+
let parent = null;
|
420 |
+
if (lineIds.length > 0) {
|
421 |
+
//compute the position of the single el (top and bottom and make a div)
|
422 |
+
const el = window.document.getElementById(lineIds[0]);
|
423 |
+
top = el.offsetTop;
|
424 |
+
height = el.offsetHeight;
|
425 |
+
parent = el.parentElement.parentElement;
|
426 |
+
if (lineIds.length > 1) {
|
427 |
+
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
|
428 |
+
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
|
429 |
+
height = bottom - top;
|
430 |
+
}
|
431 |
+
if (top !== null && height !== null && parent !== null) {
|
432 |
+
// cook up a div (if necessary) and position it
|
433 |
+
let div = window.document.getElementById("code-annotation-line-highlight");
|
434 |
+
if (div === null) {
|
435 |
+
div = window.document.createElement("div");
|
436 |
+
div.setAttribute("id", "code-annotation-line-highlight");
|
437 |
+
div.style.position = 'absolute';
|
438 |
+
parent.appendChild(div);
|
439 |
+
}
|
440 |
+
div.style.top = top - 2 + "px";
|
441 |
+
div.style.height = height + 4 + "px";
|
442 |
+
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
|
443 |
+
if (gutterDiv === null) {
|
444 |
+
gutterDiv = window.document.createElement("div");
|
445 |
+
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
|
446 |
+
gutterDiv.style.position = 'absolute';
|
447 |
+
const codeCell = window.document.getElementById(targetCell);
|
448 |
+
const gutter = codeCell.querySelector('.code-annotation-gutter');
|
449 |
+
gutter.appendChild(gutterDiv);
|
450 |
+
}
|
451 |
+
gutterDiv.style.top = top - 2 + "px";
|
452 |
+
gutterDiv.style.height = height + 4 + "px";
|
453 |
+
}
|
454 |
+
selectedAnnoteEl = annoteEl;
|
455 |
+
}
|
456 |
+
};
|
457 |
+
const unselectCodeLines = () => {
|
458 |
+
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
|
459 |
+
elementsIds.forEach((elId) => {
|
460 |
+
const div = window.document.getElementById(elId);
|
461 |
+
if (div) {
|
462 |
+
div.remove();
|
463 |
+
}
|
464 |
+
});
|
465 |
+
selectedAnnoteEl = undefined;
|
466 |
+
};
|
467 |
+
// Attach click handler to the DT
|
468 |
+
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
|
469 |
+
for (const annoteDlNode of annoteDls) {
|
470 |
+
annoteDlNode.addEventListener('click', (event) => {
|
471 |
+
const clickedEl = event.target;
|
472 |
+
if (clickedEl !== selectedAnnoteEl) {
|
473 |
+
unselectCodeLines();
|
474 |
+
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
|
475 |
+
if (activeEl) {
|
476 |
+
activeEl.classList.remove('code-annotation-active');
|
477 |
+
}
|
478 |
+
selectCodeLines(clickedEl);
|
479 |
+
clickedEl.classList.add('code-annotation-active');
|
480 |
+
} else {
|
481 |
+
// Unselect the line
|
482 |
+
unselectCodeLines();
|
483 |
+
clickedEl.classList.remove('code-annotation-active');
|
484 |
+
}
|
485 |
+
});
|
486 |
+
}
|
487 |
+
const findCites = (el) => {
|
488 |
+
const parentEl = el.parentElement;
|
489 |
+
if (parentEl) {
|
490 |
+
const cites = parentEl.dataset.cites;
|
491 |
+
if (cites) {
|
492 |
+
return {
|
493 |
+
el,
|
494 |
+
cites: cites.split(' ')
|
495 |
+
};
|
496 |
+
} else {
|
497 |
+
return findCites(el.parentElement)
|
498 |
+
}
|
499 |
+
} else {
|
500 |
+
return undefined;
|
501 |
+
}
|
502 |
+
};
|
503 |
+
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
|
504 |
+
for (var i=0; i<bibliorefs.length; i++) {
|
505 |
+
const ref = bibliorefs[i];
|
506 |
+
const citeInfo = findCites(ref);
|
507 |
+
if (citeInfo) {
|
508 |
+
tippyHover(citeInfo.el, function() {
|
509 |
+
var popup = window.document.createElement('div');
|
510 |
+
citeInfo.cites.forEach(function(cite) {
|
511 |
+
var citeDiv = window.document.createElement('div');
|
512 |
+
citeDiv.classList.add('hanging-indent');
|
513 |
+
citeDiv.classList.add('csl-entry');
|
514 |
+
var biblioDiv = window.document.getElementById('ref-' + cite);
|
515 |
+
if (biblioDiv) {
|
516 |
+
citeDiv.innerHTML = biblioDiv.innerHTML;
|
517 |
+
}
|
518 |
+
popup.appendChild(citeDiv);
|
519 |
+
});
|
520 |
+
return popup.innerHTML;
|
521 |
+
});
|
522 |
+
}
|
523 |
+
}
|
524 |
+
});
|
525 |
+
</script>
|
526 |
+
<nav class="page-navigation">
|
527 |
+
<div class="nav-page nav-page-previous">
|
528 |
+
<a href="./cw001evenodd.html" class="pagination-link">
|
529 |
+
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">1</span> <span class="chapter-title">Even or Odd</span></span>
|
530 |
+
</a>
|
531 |
+
</div>
|
532 |
+
<div class="nav-page nav-page-next">
|
533 |
+
<a href="./cw003countsheep.html" class="pagination-link">
|
534 |
+
<span class="nav-page-text"><span class="chapter-number">3</span> <span class="chapter-title">If you can’t sleep, just count sheep!!</span></span> <i class="bi bi-arrow-right-short"></i>
|
535 |
+
</a>
|
536 |
+
</div>
|
537 |
+
</nav>
|
538 |
+
</div> <!-- /content -->
|
539 |
+
|
540 |
+
|
541 |
+
|
542 |
+
</body></html>
|
cw003countsheep.html
ADDED
@@ -0,0 +1,545 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 - 3 If you can’t sleep, just count sheep!!</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="./cw004reducegrow.html" rel="next">
|
68 |
+
<link href="./cw002multiply.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 - 3 If you can’t sleep, just count sheep!!">
|
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="./cw003countsheep.html"><span class="chapter-number">3</span> <span class="chapter-title">If you can't sleep, just count sheep!!</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> <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> <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 active">
|
168 |
+
<span class="menu-text"><span class="chapter-number">3</span> <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> <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> <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> <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="./references.html" class="sidebar-item-text sidebar-link">
|
192 |
+
<span class="menu-text">References</span></a>
|
193 |
+
</div>
|
194 |
+
</li>
|
195 |
+
</ul>
|
196 |
+
</div>
|
197 |
+
</nav>
|
198 |
+
<div id="quarto-sidebar-glass" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass"></div>
|
199 |
+
<!-- margin-sidebar -->
|
200 |
+
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
|
201 |
+
<nav id="TOC" role="doc-toc" class="toc-active">
|
202 |
+
<h2 id="toc-title">Table of contents</h2>
|
203 |
+
|
204 |
+
<ul>
|
205 |
+
<li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">3.1</span> Instruction</a></li>
|
206 |
+
<li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">3.2</span> YouTube Video</a></li>
|
207 |
+
<li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">3.3</span> Solution Code</a></li>
|
208 |
+
<li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">3.4</span> Test</a></li>
|
209 |
+
<li><a href="#supported-by" id="toc-supported-by" class="nav-link" data-scroll-target="#supported-by"><span class="header-section-number">3.5</span> Supported by</a></li>
|
210 |
+
</ul>
|
211 |
+
</nav>
|
212 |
+
</div>
|
213 |
+
<!-- main -->
|
214 |
+
<main class="content" id="quarto-document-content">
|
215 |
+
|
216 |
+
<header id="title-block-header" class="quarto-title-block default">
|
217 |
+
<div class="quarto-title">
|
218 |
+
<h1 class="title"><span class="chapter-number">3</span> <span class="chapter-title">If you can’t sleep, just count sheep!!</span></h1>
|
219 |
+
</div>
|
220 |
+
|
221 |
+
|
222 |
+
|
223 |
+
<div class="quarto-title-meta">
|
224 |
+
|
225 |
+
|
226 |
+
|
227 |
+
|
228 |
+
</div>
|
229 |
+
|
230 |
+
|
231 |
+
</header>
|
232 |
+
|
233 |
+
<p>Tantangan #3/366 - 17 Feb 2024</p>
|
234 |
+
<p><a href="https://www.codewars.com/kata/5b077ebdaf15be5c7f000077/train/r" class="uri">https://www.codewars.com/kata/5b077ebdaf15be5c7f000077/train/r</a></p>
|
235 |
+
<p><span class="badge rounded-pill quarto-badge " style="background-color: grey;">8kyu</span> If you can’t sleep, just count sheep!!</p>
|
236 |
+
<section id="instruction" class="level2" data-number="3.1">
|
237 |
+
<h2 data-number="3.1" class="anchored" data-anchor-id="instruction"><span class="header-section-number">3.1</span> Instruction</h2>
|
238 |
+
<p>Given a non-negative integer, 3 for example, return a string with a murmur: “1 sheep…2 sheep…3 sheep…”. Input will always be valid, i.e. no negative integers.</p>
|
239 |
+
</section>
|
240 |
+
<section id="youtube-video" class="level2" data-number="3.2">
|
241 |
+
<h2 data-number="3.2" class="anchored" data-anchor-id="youtube-video"><span class="header-section-number">3.2</span> YouTube Video</h2>
|
242 |
+
<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>
|
243 |
+
</section>
|
244 |
+
<section id="solution-code" class="level2" data-number="3.3">
|
245 |
+
<h2 data-number="3.3" class="anchored" data-anchor-id="solution-code"><span class="header-section-number">3.3</span> Solution Code</h2>
|
246 |
+
<p>Solusi bar-bar</p>
|
247 |
+
<div class="cell">
|
248 |
+
<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>countSheep <span class="ot"><-</span> <span class="cf">function</span>(num){</span>
|
249 |
+
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span>(num <span class="sc">==</span> <span class="dv">0</span>){</span>
|
250 |
+
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="st">""</span>)</span>
|
251 |
+
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> } <span class="cf">else</span> {</span>
|
252 |
+
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> result <span class="ot"><-</span> <span class="st">""</span></span>
|
253 |
+
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span>(i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span>num){</span>
|
254 |
+
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> result <span class="ot"><-</span> <span class="fu">paste</span>(result, i, <span class="st">" sheep..."</span>, <span class="at">sep =</span> <span class="st">""</span>)</span>
|
255 |
+
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> }</span>
|
256 |
+
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(result)</span>
|
257 |
+
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> }</span>
|
258 |
+
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
259 |
+
</div>
|
260 |
+
<p>Solusi simple</p>
|
261 |
+
<div class="cell">
|
262 |
+
<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>countSheep <span class="ot"><-</span> <span class="cf">function</span>(num){</span>
|
263 |
+
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">ifelse</span>(num <span class="sc">==</span> <span class="dv">0</span>, <span class="st">""</span>, <span class="fu">paste</span>(<span class="dv">1</span><span class="sc">:</span>num, <span class="st">"sheep..."</span>, <span class="at">collapse =</span> <span class="st">""</span>))</span>
|
264 |
+
<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>
|
265 |
+
</div>
|
266 |
+
</section>
|
267 |
+
<section id="test" class="level2" data-number="3.4">
|
268 |
+
<h2 data-number="3.4" class="anchored" data-anchor-id="test"><span class="header-section-number">3.4</span> Test</h2>
|
269 |
+
<div class="cell">
|
270 |
+
<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>
|
271 |
+
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
|
272 |
+
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">"Fixed tests"</span>, {</span>
|
273 |
+
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">countSheep</span>(<span class="dv">0</span>), <span class="st">""</span>)</span>
|
274 |
+
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">countSheep</span>(<span class="dv">1</span>), <span class="st">"1 sheep..."</span>)</span>
|
275 |
+
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">countSheep</span>(<span class="dv">2</span>), <span class="st">"1 sheep...2 sheep..."</span>)</span>
|
276 |
+
<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>
|
277 |
+
<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>
|
278 |
+
<div class="cell-output cell-output-stdout">
|
279 |
+
<pre><code>Test passed 😀</code></pre>
|
280 |
+
</div>
|
281 |
+
</div>
|
282 |
+
</section>
|
283 |
+
<section id="supported-by" class="level2" data-number="3.5">
|
284 |
+
<h2 data-number="3.5" class="anchored" data-anchor-id="supported-by"><span class="header-section-number">3.5</span> Supported by</h2>
|
285 |
+
<div class="quarto-figure quarto-figure-center">
|
286 |
+
<figure class="figure">
|
287 |
+
<p><a href="https://www.starcore.co"><img src="new_starcore_logo.png" class="img-fluid figure-img"></a></p>
|
288 |
+
<figcaption class="figure-caption">StarCore Analytics</figcaption>
|
289 |
+
</figure>
|
290 |
+
</div>
|
291 |
+
|
292 |
+
|
293 |
+
</section>
|
294 |
+
|
295 |
+
</main> <!-- /main -->
|
296 |
+
<script id="quarto-html-after-body" type="application/javascript">
|
297 |
+
window.document.addEventListener("DOMContentLoaded", function (event) {
|
298 |
+
const toggleBodyColorMode = (bsSheetEl) => {
|
299 |
+
const mode = bsSheetEl.getAttribute("data-mode");
|
300 |
+
const bodyEl = window.document.querySelector("body");
|
301 |
+
if (mode === "dark") {
|
302 |
+
bodyEl.classList.add("quarto-dark");
|
303 |
+
bodyEl.classList.remove("quarto-light");
|
304 |
+
} else {
|
305 |
+
bodyEl.classList.add("quarto-light");
|
306 |
+
bodyEl.classList.remove("quarto-dark");
|
307 |
+
}
|
308 |
+
}
|
309 |
+
const toggleBodyColorPrimary = () => {
|
310 |
+
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
|
311 |
+
if (bsSheetEl) {
|
312 |
+
toggleBodyColorMode(bsSheetEl);
|
313 |
+
}
|
314 |
+
}
|
315 |
+
toggleBodyColorPrimary();
|
316 |
+
const icon = "";
|
317 |
+
const anchorJS = new window.AnchorJS();
|
318 |
+
anchorJS.options = {
|
319 |
+
placement: 'right',
|
320 |
+
icon: icon
|
321 |
+
};
|
322 |
+
anchorJS.add('.anchored');
|
323 |
+
const isCodeAnnotation = (el) => {
|
324 |
+
for (const clz of el.classList) {
|
325 |
+
if (clz.startsWith('code-annotation-')) {
|
326 |
+
return true;
|
327 |
+
}
|
328 |
+
}
|
329 |
+
return false;
|
330 |
+
}
|
331 |
+
const clipboard = new window.ClipboardJS('.code-copy-button', {
|
332 |
+
text: function(trigger) {
|
333 |
+
const codeEl = trigger.previousElementSibling.cloneNode(true);
|
334 |
+
for (const childEl of codeEl.children) {
|
335 |
+
if (isCodeAnnotation(childEl)) {
|
336 |
+
childEl.remove();
|
337 |
+
}
|
338 |
+
}
|
339 |
+
return codeEl.innerText;
|
340 |
+
}
|
341 |
+
});
|
342 |
+
clipboard.on('success', function(e) {
|
343 |
+
// button target
|
344 |
+
const button = e.trigger;
|
345 |
+
// don't keep focus
|
346 |
+
button.blur();
|
347 |
+
// flash "checked"
|
348 |
+
button.classList.add('code-copy-button-checked');
|
349 |
+
var currentTitle = button.getAttribute("title");
|
350 |
+
button.setAttribute("title", "Copied!");
|
351 |
+
let tooltip;
|
352 |
+
if (window.bootstrap) {
|
353 |
+
button.setAttribute("data-bs-toggle", "tooltip");
|
354 |
+
button.setAttribute("data-bs-placement", "left");
|
355 |
+
button.setAttribute("data-bs-title", "Copied!");
|
356 |
+
tooltip = new bootstrap.Tooltip(button,
|
357 |
+
{ trigger: "manual",
|
358 |
+
customClass: "code-copy-button-tooltip",
|
359 |
+
offset: [0, -8]});
|
360 |
+
tooltip.show();
|
361 |
+
}
|
362 |
+
setTimeout(function() {
|
363 |
+
if (tooltip) {
|
364 |
+
tooltip.hide();
|
365 |
+
button.removeAttribute("data-bs-title");
|
366 |
+
button.removeAttribute("data-bs-toggle");
|
367 |
+
button.removeAttribute("data-bs-placement");
|
368 |
+
}
|
369 |
+
button.setAttribute("title", currentTitle);
|
370 |
+
button.classList.remove('code-copy-button-checked');
|
371 |
+
}, 1000);
|
372 |
+
// clear code selection
|
373 |
+
e.clearSelection();
|
374 |
+
});
|
375 |
+
function tippyHover(el, contentFn) {
|
376 |
+
const config = {
|
377 |
+
allowHTML: true,
|
378 |
+
content: contentFn,
|
379 |
+
maxWidth: 500,
|
380 |
+
delay: 100,
|
381 |
+
arrow: false,
|
382 |
+
appendTo: function(el) {
|
383 |
+
return el.parentElement;
|
384 |
+
},
|
385 |
+
interactive: true,
|
386 |
+
interactiveBorder: 10,
|
387 |
+
theme: 'quarto',
|
388 |
+
placement: 'bottom-start'
|
389 |
+
};
|
390 |
+
window.tippy(el, config);
|
391 |
+
}
|
392 |
+
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
|
393 |
+
for (var i=0; i<noterefs.length; i++) {
|
394 |
+
const ref = noterefs[i];
|
395 |
+
tippyHover(ref, function() {
|
396 |
+
// use id or data attribute instead here
|
397 |
+
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
|
398 |
+
try { href = new URL(href).hash; } catch {}
|
399 |
+
const id = href.replace(/^#\/?/, "");
|
400 |
+
const note = window.document.getElementById(id);
|
401 |
+
return note.innerHTML;
|
402 |
+
});
|
403 |
+
}
|
404 |
+
let selectedAnnoteEl;
|
405 |
+
const selectorForAnnotation = ( cell, annotation) => {
|
406 |
+
let cellAttr = 'data-code-cell="' + cell + '"';
|
407 |
+
let lineAttr = 'data-code-annotation="' + annotation + '"';
|
408 |
+
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
|
409 |
+
return selector;
|
410 |
+
}
|
411 |
+
const selectCodeLines = (annoteEl) => {
|
412 |
+
const doc = window.document;
|
413 |
+
const targetCell = annoteEl.getAttribute("data-target-cell");
|
414 |
+
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
|
415 |
+
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
|
416 |
+
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
|
417 |
+
const lineIds = lines.map((line) => {
|
418 |
+
return targetCell + "-" + line;
|
419 |
+
})
|
420 |
+
let top = null;
|
421 |
+
let height = null;
|
422 |
+
let parent = null;
|
423 |
+
if (lineIds.length > 0) {
|
424 |
+
//compute the position of the single el (top and bottom and make a div)
|
425 |
+
const el = window.document.getElementById(lineIds[0]);
|
426 |
+
top = el.offsetTop;
|
427 |
+
height = el.offsetHeight;
|
428 |
+
parent = el.parentElement.parentElement;
|
429 |
+
if (lineIds.length > 1) {
|
430 |
+
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
|
431 |
+
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
|
432 |
+
height = bottom - top;
|
433 |
+
}
|
434 |
+
if (top !== null && height !== null && parent !== null) {
|
435 |
+
// cook up a div (if necessary) and position it
|
436 |
+
let div = window.document.getElementById("code-annotation-line-highlight");
|
437 |
+
if (div === null) {
|
438 |
+
div = window.document.createElement("div");
|
439 |
+
div.setAttribute("id", "code-annotation-line-highlight");
|
440 |
+
div.style.position = 'absolute';
|
441 |
+
parent.appendChild(div);
|
442 |
+
}
|
443 |
+
div.style.top = top - 2 + "px";
|
444 |
+
div.style.height = height + 4 + "px";
|
445 |
+
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
|
446 |
+
if (gutterDiv === null) {
|
447 |
+
gutterDiv = window.document.createElement("div");
|
448 |
+
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
|
449 |
+
gutterDiv.style.position = 'absolute';
|
450 |
+
const codeCell = window.document.getElementById(targetCell);
|
451 |
+
const gutter = codeCell.querySelector('.code-annotation-gutter');
|
452 |
+
gutter.appendChild(gutterDiv);
|
453 |
+
}
|
454 |
+
gutterDiv.style.top = top - 2 + "px";
|
455 |
+
gutterDiv.style.height = height + 4 + "px";
|
456 |
+
}
|
457 |
+
selectedAnnoteEl = annoteEl;
|
458 |
+
}
|
459 |
+
};
|
460 |
+
const unselectCodeLines = () => {
|
461 |
+
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
|
462 |
+
elementsIds.forEach((elId) => {
|
463 |
+
const div = window.document.getElementById(elId);
|
464 |
+
if (div) {
|
465 |
+
div.remove();
|
466 |
+
}
|
467 |
+
});
|
468 |
+
selectedAnnoteEl = undefined;
|
469 |
+
};
|
470 |
+
// Attach click handler to the DT
|
471 |
+
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
|
472 |
+
for (const annoteDlNode of annoteDls) {
|
473 |
+
annoteDlNode.addEventListener('click', (event) => {
|
474 |
+
const clickedEl = event.target;
|
475 |
+
if (clickedEl !== selectedAnnoteEl) {
|
476 |
+
unselectCodeLines();
|
477 |
+
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
|
478 |
+
if (activeEl) {
|
479 |
+
activeEl.classList.remove('code-annotation-active');
|
480 |
+
}
|
481 |
+
selectCodeLines(clickedEl);
|
482 |
+
clickedEl.classList.add('code-annotation-active');
|
483 |
+
} else {
|
484 |
+
// Unselect the line
|
485 |
+
unselectCodeLines();
|
486 |
+
clickedEl.classList.remove('code-annotation-active');
|
487 |
+
}
|
488 |
+
});
|
489 |
+
}
|
490 |
+
const findCites = (el) => {
|
491 |
+
const parentEl = el.parentElement;
|
492 |
+
if (parentEl) {
|
493 |
+
const cites = parentEl.dataset.cites;
|
494 |
+
if (cites) {
|
495 |
+
return {
|
496 |
+
el,
|
497 |
+
cites: cites.split(' ')
|
498 |
+
};
|
499 |
+
} else {
|
500 |
+
return findCites(el.parentElement)
|
501 |
+
}
|
502 |
+
} else {
|
503 |
+
return undefined;
|
504 |
+
}
|
505 |
+
};
|
506 |
+
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
|
507 |
+
for (var i=0; i<bibliorefs.length; i++) {
|
508 |
+
const ref = bibliorefs[i];
|
509 |
+
const citeInfo = findCites(ref);
|
510 |
+
if (citeInfo) {
|
511 |
+
tippyHover(citeInfo.el, function() {
|
512 |
+
var popup = window.document.createElement('div');
|
513 |
+
citeInfo.cites.forEach(function(cite) {
|
514 |
+
var citeDiv = window.document.createElement('div');
|
515 |
+
citeDiv.classList.add('hanging-indent');
|
516 |
+
citeDiv.classList.add('csl-entry');
|
517 |
+
var biblioDiv = window.document.getElementById('ref-' + cite);
|
518 |
+
if (biblioDiv) {
|
519 |
+
citeDiv.innerHTML = biblioDiv.innerHTML;
|
520 |
+
}
|
521 |
+
popup.appendChild(citeDiv);
|
522 |
+
});
|
523 |
+
return popup.innerHTML;
|
524 |
+
});
|
525 |
+
}
|
526 |
+
}
|
527 |
+
});
|
528 |
+
</script>
|
529 |
+
<nav class="page-navigation">
|
530 |
+
<div class="nav-page nav-page-previous">
|
531 |
+
<a href="./cw002multiply.html" class="pagination-link">
|
532 |
+
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">2</span> <span class="chapter-title">Multiply</span></span>
|
533 |
+
</a>
|
534 |
+
</div>
|
535 |
+
<div class="nav-page nav-page-next">
|
536 |
+
<a href="./cw004reducegrow.html" class="pagination-link">
|
537 |
+
<span class="nav-page-text"><span class="chapter-number">4</span> <span class="chapter-title">Beginner - Reduce but Grow</span></span> <i class="bi bi-arrow-right-short"></i>
|
538 |
+
</a>
|
539 |
+
</div>
|
540 |
+
</nav>
|
541 |
+
</div> <!-- /content -->
|
542 |
+
|
543 |
+
|
544 |
+
|
545 |
+
</body></html>
|
cw004reducegrow.html
ADDED
@@ -0,0 +1,539 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 - 4 Beginner - Reduce but Grow</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="./cw005make_negative.html" rel="next">
|
68 |
+
<link href="./cw003countsheep.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 - 4 Beginner - Reduce but Grow">
|
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="./cw004reducegrow.html"><span class="chapter-number">4</span> <span class="chapter-title">Beginner - Reduce but Grow</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> <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> <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> <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 active">
|
174 |
+
<span class="menu-text"><span class="chapter-number">4</span> <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> <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> <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="./references.html" class="sidebar-item-text sidebar-link">
|
192 |
+
<span class="menu-text">References</span></a>
|
193 |
+
</div>
|
194 |
+
</li>
|
195 |
+
</ul>
|
196 |
+
</div>
|
197 |
+
</nav>
|
198 |
+
<div id="quarto-sidebar-glass" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass"></div>
|
199 |
+
<!-- margin-sidebar -->
|
200 |
+
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
|
201 |
+
<nav id="TOC" role="doc-toc" class="toc-active">
|
202 |
+
<h2 id="toc-title">Table of contents</h2>
|
203 |
+
|
204 |
+
<ul>
|
205 |
+
<li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">4.1</span> Instruction</a></li>
|
206 |
+
<li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">4.2</span> YouTube Video</a></li>
|
207 |
+
<li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">4.3</span> Solution Code</a></li>
|
208 |
+
<li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">4.4</span> Test</a></li>
|
209 |
+
<li><a href="#supported-by" id="toc-supported-by" class="nav-link" data-scroll-target="#supported-by"><span class="header-section-number">4.5</span> Supported by</a></li>
|
210 |
+
</ul>
|
211 |
+
</nav>
|
212 |
+
</div>
|
213 |
+
<!-- main -->
|
214 |
+
<main class="content" id="quarto-document-content">
|
215 |
+
|
216 |
+
<header id="title-block-header" class="quarto-title-block default">
|
217 |
+
<div class="quarto-title">
|
218 |
+
<h1 class="title"><span id="reducegrow" class="quarto-section-identifier"><span class="chapter-number">4</span> <span class="chapter-title">Beginner - Reduce but Grow</span></span></h1>
|
219 |
+
</div>
|
220 |
+
|
221 |
+
|
222 |
+
|
223 |
+
<div class="quarto-title-meta">
|
224 |
+
|
225 |
+
|
226 |
+
|
227 |
+
|
228 |
+
</div>
|
229 |
+
|
230 |
+
|
231 |
+
</header>
|
232 |
+
|
233 |
+
<p>Tantangan #4/366 - 15 Feb 2024</p>
|
234 |
+
<p><a href="https://www.codewars.com/kata/57f780909f7e8e3183000078/train/r" class="uri">https://www.codewars.com/kata/57f780909f7e8e3183000078/train/r</a></p>
|
235 |
+
<p><span class="badge rounded-pill quarto-badge " style="background-color: grey;">8kyu</span> Beginner - Reduce but Grow</p>
|
236 |
+
<section id="instruction" class="level2" data-number="4.1">
|
237 |
+
<h2 data-number="4.1" class="anchored" data-anchor-id="instruction"><span class="header-section-number">4.1</span> Instruction</h2>
|
238 |
+
<p>Given a non-empty array of integers, return the result of multiplying the values together in order. Example:</p>
|
239 |
+
<pre><code>[1, 2, 3, 4] => 1 * 2 * 3 * 4 = 24</code></pre>
|
240 |
+
</section>
|
241 |
+
<section id="youtube-video" class="level2" data-number="4.2">
|
242 |
+
<h2 data-number="4.2" class="anchored" data-anchor-id="youtube-video"><span class="header-section-number">4.2</span> YouTube Video</h2>
|
243 |
+
<div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/xCvHwR52p4k?si=yoLfpHfcIBYk0j9c" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
|
244 |
+
</section>
|
245 |
+
<section id="solution-code" class="level2" data-number="4.3">
|
246 |
+
<h2 data-number="4.3" class="anchored" data-anchor-id="solution-code"><span class="header-section-number">4.3</span> Solution Code</h2>
|
247 |
+
<p>Solusi bar-bar</p>
|
248 |
+
<div class="cell">
|
249 |
+
<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>grow <span class="ot"><-</span> <span class="cf">function</span>(arr) {</span>
|
250 |
+
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> result <span class="ot"><-</span> <span class="dv">1</span></span>
|
251 |
+
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span>(i <span class="cf">in</span> arr){</span>
|
252 |
+
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a> result <span class="ot"><-</span> result <span class="sc">*</span> i</span>
|
253 |
+
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> }</span>
|
254 |
+
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(result)</span>
|
255 |
+
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
256 |
+
</div>
|
257 |
+
<p>Solusi simple</p>
|
258 |
+
<div class="cell">
|
259 |
+
<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="co"># grow <- function(arr) prod(arr)</span></span>
|
260 |
+
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>grow <span class="ot"><-</span> prod</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
261 |
+
</div>
|
262 |
+
</section>
|
263 |
+
<section id="test" class="level2" data-number="4.4">
|
264 |
+
<h2 data-number="4.4" class="anchored" data-anchor-id="test"><span class="header-section-number">4.4</span> Test</h2>
|
265 |
+
<div class="cell">
|
266 |
+
<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>
|
267 |
+
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">"basic tests"</span>, {</span>
|
268 |
+
<span id="cb4-3"><a href="#cb4-3" 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">1</span>, <span class="dv">2</span>, <span class="dv">3</span>)), <span class="dv">6</span>)</span>
|
269 |
+
<span id="cb4-4"><a href="#cb4-4" 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">4</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">1</span>, <span class="dv">4</span>)), <span class="dv">16</span>)</span>
|
270 |
+
<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>
|
271 |
+
<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>
|
272 |
+
<div class="cell-output cell-output-stdout">
|
273 |
+
<pre><code>Test passed 🎉</code></pre>
|
274 |
+
</div>
|
275 |
+
</div>
|
276 |
+
</section>
|
277 |
+
<section id="supported-by" class="level2" data-number="4.5">
|
278 |
+
<h2 data-number="4.5" class="anchored" data-anchor-id="supported-by"><span class="header-section-number">4.5</span> Supported by</h2>
|
279 |
+
<div class="quarto-figure quarto-figure-center">
|
280 |
+
<figure class="figure">
|
281 |
+
<p><a href="https://www.starcore.co"><img src="new_starcore_logo.png" class="img-fluid figure-img"></a></p>
|
282 |
+
<figcaption class="figure-caption">StarCore Analytics</figcaption>
|
283 |
+
</figure>
|
284 |
+
</div>
|
285 |
+
|
286 |
+
|
287 |
+
</section>
|
288 |
+
|
289 |
+
</main> <!-- /main -->
|
290 |
+
<script id="quarto-html-after-body" type="application/javascript">
|
291 |
+
window.document.addEventListener("DOMContentLoaded", function (event) {
|
292 |
+
const toggleBodyColorMode = (bsSheetEl) => {
|
293 |
+
const mode = bsSheetEl.getAttribute("data-mode");
|
294 |
+
const bodyEl = window.document.querySelector("body");
|
295 |
+
if (mode === "dark") {
|
296 |
+
bodyEl.classList.add("quarto-dark");
|
297 |
+
bodyEl.classList.remove("quarto-light");
|
298 |
+
} else {
|
299 |
+
bodyEl.classList.add("quarto-light");
|
300 |
+
bodyEl.classList.remove("quarto-dark");
|
301 |
+
}
|
302 |
+
}
|
303 |
+
const toggleBodyColorPrimary = () => {
|
304 |
+
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
|
305 |
+
if (bsSheetEl) {
|
306 |
+
toggleBodyColorMode(bsSheetEl);
|
307 |
+
}
|
308 |
+
}
|
309 |
+
toggleBodyColorPrimary();
|
310 |
+
const icon = "";
|
311 |
+
const anchorJS = new window.AnchorJS();
|
312 |
+
anchorJS.options = {
|
313 |
+
placement: 'right',
|
314 |
+
icon: icon
|
315 |
+
};
|
316 |
+
anchorJS.add('.anchored');
|
317 |
+
const isCodeAnnotation = (el) => {
|
318 |
+
for (const clz of el.classList) {
|
319 |
+
if (clz.startsWith('code-annotation-')) {
|
320 |
+
return true;
|
321 |
+
}
|
322 |
+
}
|
323 |
+
return false;
|
324 |
+
}
|
325 |
+
const clipboard = new window.ClipboardJS('.code-copy-button', {
|
326 |
+
text: function(trigger) {
|
327 |
+
const codeEl = trigger.previousElementSibling.cloneNode(true);
|
328 |
+
for (const childEl of codeEl.children) {
|
329 |
+
if (isCodeAnnotation(childEl)) {
|
330 |
+
childEl.remove();
|
331 |
+
}
|
332 |
+
}
|
333 |
+
return codeEl.innerText;
|
334 |
+
}
|
335 |
+
});
|
336 |
+
clipboard.on('success', function(e) {
|
337 |
+
// button target
|
338 |
+
const button = e.trigger;
|
339 |
+
// don't keep focus
|
340 |
+
button.blur();
|
341 |
+
// flash "checked"
|
342 |
+
button.classList.add('code-copy-button-checked');
|
343 |
+
var currentTitle = button.getAttribute("title");
|
344 |
+
button.setAttribute("title", "Copied!");
|
345 |
+
let tooltip;
|
346 |
+
if (window.bootstrap) {
|
347 |
+
button.setAttribute("data-bs-toggle", "tooltip");
|
348 |
+
button.setAttribute("data-bs-placement", "left");
|
349 |
+
button.setAttribute("data-bs-title", "Copied!");
|
350 |
+
tooltip = new bootstrap.Tooltip(button,
|
351 |
+
{ trigger: "manual",
|
352 |
+
customClass: "code-copy-button-tooltip",
|
353 |
+
offset: [0, -8]});
|
354 |
+
tooltip.show();
|
355 |
+
}
|
356 |
+
setTimeout(function() {
|
357 |
+
if (tooltip) {
|
358 |
+
tooltip.hide();
|
359 |
+
button.removeAttribute("data-bs-title");
|
360 |
+
button.removeAttribute("data-bs-toggle");
|
361 |
+
button.removeAttribute("data-bs-placement");
|
362 |
+
}
|
363 |
+
button.setAttribute("title", currentTitle);
|
364 |
+
button.classList.remove('code-copy-button-checked');
|
365 |
+
}, 1000);
|
366 |
+
// clear code selection
|
367 |
+
e.clearSelection();
|
368 |
+
});
|
369 |
+
function tippyHover(el, contentFn) {
|
370 |
+
const config = {
|
371 |
+
allowHTML: true,
|
372 |
+
content: contentFn,
|
373 |
+
maxWidth: 500,
|
374 |
+
delay: 100,
|
375 |
+
arrow: false,
|
376 |
+
appendTo: function(el) {
|
377 |
+
return el.parentElement;
|
378 |
+
},
|
379 |
+
interactive: true,
|
380 |
+
interactiveBorder: 10,
|
381 |
+
theme: 'quarto',
|
382 |
+
placement: 'bottom-start'
|
383 |
+
};
|
384 |
+
window.tippy(el, config);
|
385 |
+
}
|
386 |
+
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
|
387 |
+
for (var i=0; i<noterefs.length; i++) {
|
388 |
+
const ref = noterefs[i];
|
389 |
+
tippyHover(ref, function() {
|
390 |
+
// use id or data attribute instead here
|
391 |
+
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
|
392 |
+
try { href = new URL(href).hash; } catch {}
|
393 |
+
const id = href.replace(/^#\/?/, "");
|
394 |
+
const note = window.document.getElementById(id);
|
395 |
+
return note.innerHTML;
|
396 |
+
});
|
397 |
+
}
|
398 |
+
let selectedAnnoteEl;
|
399 |
+
const selectorForAnnotation = ( cell, annotation) => {
|
400 |
+
let cellAttr = 'data-code-cell="' + cell + '"';
|
401 |
+
let lineAttr = 'data-code-annotation="' + annotation + '"';
|
402 |
+
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
|
403 |
+
return selector;
|
404 |
+
}
|
405 |
+
const selectCodeLines = (annoteEl) => {
|
406 |
+
const doc = window.document;
|
407 |
+
const targetCell = annoteEl.getAttribute("data-target-cell");
|
408 |
+
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
|
409 |
+
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
|
410 |
+
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
|
411 |
+
const lineIds = lines.map((line) => {
|
412 |
+
return targetCell + "-" + line;
|
413 |
+
})
|
414 |
+
let top = null;
|
415 |
+
let height = null;
|
416 |
+
let parent = null;
|
417 |
+
if (lineIds.length > 0) {
|
418 |
+
//compute the position of the single el (top and bottom and make a div)
|
419 |
+
const el = window.document.getElementById(lineIds[0]);
|
420 |
+
top = el.offsetTop;
|
421 |
+
height = el.offsetHeight;
|
422 |
+
parent = el.parentElement.parentElement;
|
423 |
+
if (lineIds.length > 1) {
|
424 |
+
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
|
425 |
+
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
|
426 |
+
height = bottom - top;
|
427 |
+
}
|
428 |
+
if (top !== null && height !== null && parent !== null) {
|
429 |
+
// cook up a div (if necessary) and position it
|
430 |
+
let div = window.document.getElementById("code-annotation-line-highlight");
|
431 |
+
if (div === null) {
|
432 |
+
div = window.document.createElement("div");
|
433 |
+
div.setAttribute("id", "code-annotation-line-highlight");
|
434 |
+
div.style.position = 'absolute';
|
435 |
+
parent.appendChild(div);
|
436 |
+
}
|
437 |
+
div.style.top = top - 2 + "px";
|
438 |
+
div.style.height = height + 4 + "px";
|
439 |
+
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
|
440 |
+
if (gutterDiv === null) {
|
441 |
+
gutterDiv = window.document.createElement("div");
|
442 |
+
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
|
443 |
+
gutterDiv.style.position = 'absolute';
|
444 |
+
const codeCell = window.document.getElementById(targetCell);
|
445 |
+
const gutter = codeCell.querySelector('.code-annotation-gutter');
|
446 |
+
gutter.appendChild(gutterDiv);
|
447 |
+
}
|
448 |
+
gutterDiv.style.top = top - 2 + "px";
|
449 |
+
gutterDiv.style.height = height + 4 + "px";
|
450 |
+
}
|
451 |
+
selectedAnnoteEl = annoteEl;
|
452 |
+
}
|
453 |
+
};
|
454 |
+
const unselectCodeLines = () => {
|
455 |
+
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
|
456 |
+
elementsIds.forEach((elId) => {
|
457 |
+
const div = window.document.getElementById(elId);
|
458 |
+
if (div) {
|
459 |
+
div.remove();
|
460 |
+
}
|
461 |
+
});
|
462 |
+
selectedAnnoteEl = undefined;
|
463 |
+
};
|
464 |
+
// Attach click handler to the DT
|
465 |
+
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
|
466 |
+
for (const annoteDlNode of annoteDls) {
|
467 |
+
annoteDlNode.addEventListener('click', (event) => {
|
468 |
+
const clickedEl = event.target;
|
469 |
+
if (clickedEl !== selectedAnnoteEl) {
|
470 |
+
unselectCodeLines();
|
471 |
+
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
|
472 |
+
if (activeEl) {
|
473 |
+
activeEl.classList.remove('code-annotation-active');
|
474 |
+
}
|
475 |
+
selectCodeLines(clickedEl);
|
476 |
+
clickedEl.classList.add('code-annotation-active');
|
477 |
+
} else {
|
478 |
+
// Unselect the line
|
479 |
+
unselectCodeLines();
|
480 |
+
clickedEl.classList.remove('code-annotation-active');
|
481 |
+
}
|
482 |
+
});
|
483 |
+
}
|
484 |
+
const findCites = (el) => {
|
485 |
+
const parentEl = el.parentElement;
|
486 |
+
if (parentEl) {
|
487 |
+
const cites = parentEl.dataset.cites;
|
488 |
+
if (cites) {
|
489 |
+
return {
|
490 |
+
el,
|
491 |
+
cites: cites.split(' ')
|
492 |
+
};
|
493 |
+
} else {
|
494 |
+
return findCites(el.parentElement)
|
495 |
+
}
|
496 |
+
} else {
|
497 |
+
return undefined;
|
498 |
+
}
|
499 |
+
};
|
500 |
+
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
|
501 |
+
for (var i=0; i<bibliorefs.length; i++) {
|
502 |
+
const ref = bibliorefs[i];
|
503 |
+
const citeInfo = findCites(ref);
|
504 |
+
if (citeInfo) {
|
505 |
+
tippyHover(citeInfo.el, function() {
|
506 |
+
var popup = window.document.createElement('div');
|
507 |
+
citeInfo.cites.forEach(function(cite) {
|
508 |
+
var citeDiv = window.document.createElement('div');
|
509 |
+
citeDiv.classList.add('hanging-indent');
|
510 |
+
citeDiv.classList.add('csl-entry');
|
511 |
+
var biblioDiv = window.document.getElementById('ref-' + cite);
|
512 |
+
if (biblioDiv) {
|
513 |
+
citeDiv.innerHTML = biblioDiv.innerHTML;
|
514 |
+
}
|
515 |
+
popup.appendChild(citeDiv);
|
516 |
+
});
|
517 |
+
return popup.innerHTML;
|
518 |
+
});
|
519 |
+
}
|
520 |
+
}
|
521 |
+
});
|
522 |
+
</script>
|
523 |
+
<nav class="page-navigation">
|
524 |
+
<div class="nav-page nav-page-previous">
|
525 |
+
<a href="./cw003countsheep.html" class="pagination-link">
|
526 |
+
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">3</span> <span class="chapter-title">If you can’t sleep, just count sheep!!</span></span>
|
527 |
+
</a>
|
528 |
+
</div>
|
529 |
+
<div class="nav-page nav-page-next">
|
530 |
+
<a href="./cw005make_negative.html" class="pagination-link">
|
531 |
+
<span class="nav-page-text"><span class="chapter-number">5</span> <span class="chapter-title">Return Negative</span></span> <i class="bi bi-arrow-right-short"></i>
|
532 |
+
</a>
|
533 |
+
</div>
|
534 |
+
</nav>
|
535 |
+
</div> <!-- /content -->
|
536 |
+
|
537 |
+
|
538 |
+
|
539 |
+
</body></html>
|
cw005make_negative.html
ADDED
@@ -0,0 +1,542 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 - 5 Return Negative</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="./cw006positive_sum.html" rel="next">
|
68 |
+
<link href="./cw004reducegrow.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 - 5 Return Negative">
|
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="./cw005make_negative.html"><span class="chapter-number">5</span> <span class="chapter-title">Return Negative</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> <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> <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> <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> <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 active">
|
180 |
+
<span class="menu-text"><span class="chapter-number">5</span> <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> <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="./references.html" class="sidebar-item-text sidebar-link">
|
192 |
+
<span class="menu-text">References</span></a>
|
193 |
+
</div>
|
194 |
+
</li>
|
195 |
+
</ul>
|
196 |
+
</div>
|
197 |
+
</nav>
|
198 |
+
<div id="quarto-sidebar-glass" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass"></div>
|
199 |
+
<!-- margin-sidebar -->
|
200 |
+
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
|
201 |
+
<nav id="TOC" role="doc-toc" class="toc-active">
|
202 |
+
<h2 id="toc-title">Table of contents</h2>
|
203 |
+
|
204 |
+
<ul>
|
205 |
+
<li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">5.1</span> Instruction</a></li>
|
206 |
+
<li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">5.2</span> YouTube Video</a></li>
|
207 |
+
<li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">5.3</span> Solution Code</a></li>
|
208 |
+
<li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">5.4</span> Test</a></li>
|
209 |
+
<li><a href="#supported-by" id="toc-supported-by" class="nav-link" data-scroll-target="#supported-by"><span class="header-section-number">5.5</span> Supported by</a></li>
|
210 |
+
</ul>
|
211 |
+
</nav>
|
212 |
+
</div>
|
213 |
+
<!-- main -->
|
214 |
+
<main class="content" id="quarto-document-content">
|
215 |
+
|
216 |
+
<header id="title-block-header" class="quarto-title-block default">
|
217 |
+
<div class="quarto-title">
|
218 |
+
<h1 class="title"><span class="chapter-number">5</span> <span class="chapter-title">Return Negative</span></h1>
|
219 |
+
</div>
|
220 |
+
|
221 |
+
|
222 |
+
|
223 |
+
<div class="quarto-title-meta">
|
224 |
+
|
225 |
+
|
226 |
+
|
227 |
+
|
228 |
+
</div>
|
229 |
+
|
230 |
+
|
231 |
+
</header>
|
232 |
+
|
233 |
+
<p>Tantangan #5/366 - 18 Feb 2024</p>
|
234 |
+
<p><a href="https://www.codewars.com/kata/55685cd7ad70877c23000102/train/r" class="uri">https://www.codewars.com/kata/55685cd7ad70877c23000102/train/r</a></p>
|
235 |
+
<p><span class="badge rounded-pill quarto-badge " style="background-color: grey;">8kyu</span> Return Negative</p>
|
236 |
+
<section id="instruction" class="level2" data-number="5.1">
|
237 |
+
<h2 data-number="5.1" class="anchored" data-anchor-id="instruction"><span class="header-section-number">5.1</span> Instruction</h2>
|
238 |
+
<p>In this simple assignment you are given a number and have to make it negative. But maybe the number is already negative?</p>
|
239 |
+
<p>Examples</p>
|
240 |
+
<pre><code>make_negative(1); # return -1
|
241 |
+
make_negative(-5); # return -5
|
242 |
+
make_negative(0); # return 0</code></pre>
|
243 |
+
<p><strong>Notes</strong><br>
|
244 |
+
The number can be negative already, in which case no change is required. Zero (0) is not checked for any specific sign. Negative zeros make no mathematical sense.</p>
|
245 |
+
</section>
|
246 |
+
<section id="youtube-video" class="level2" data-number="5.2">
|
247 |
+
<h2 data-number="5.2" class="anchored" data-anchor-id="youtube-video"><span class="header-section-number">5.2</span> YouTube Video</h2>
|
248 |
+
<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>
|
249 |
+
</section>
|
250 |
+
<section id="solution-code" class="level2" data-number="5.3">
|
251 |
+
<h2 data-number="5.3" class="anchored" data-anchor-id="solution-code"><span class="header-section-number">5.3</span> Solution Code</h2>
|
252 |
+
<p>Solusi bar-bar</p>
|
253 |
+
<div class="cell">
|
254 |
+
<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>make_negative <span class="ot"><-</span> <span class="cf">function</span>(num){</span>
|
255 |
+
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">ifelse</span>(num <span class="sc"><=</span> <span class="dv">0</span>, num, <span class="sc">-</span><span class="dv">1</span><span class="sc">*</span>num)</span>
|
256 |
+
<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>
|
257 |
+
</div>
|
258 |
+
<p>Solusi simple</p>
|
259 |
+
<div class="cell">
|
260 |
+
<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>make_negative <span class="ot"><-</span> <span class="cf">function</span>(num)<span class="sc">-</span><span class="fu">abs</span>(num)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
261 |
+
</div>
|
262 |
+
</section>
|
263 |
+
<section id="test" class="level2" data-number="5.4">
|
264 |
+
<h2 data-number="5.4" class="anchored" data-anchor-id="test"><span class="header-section-number">5.4</span> Test</h2>
|
265 |
+
<div class="cell">
|
266 |
+
<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>
|
267 |
+
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
|
268 |
+
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">'Basic tests'</span>, {</span>
|
269 |
+
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">make_negative</span>(<span class="dv">42</span>), <span class="sc">-</span><span class="dv">42</span>)</span>
|
270 |
+
<span id="cb4-5"><a href="#cb4-5" 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">9</span>), <span class="sc">-</span><span class="dv">9</span>)</span>
|
271 |
+
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">make_negative</span>(<span class="dv">0</span>), <span class="dv">0</span>)</span>
|
272 |
+
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">expect_equal</span>(<span class="fu">make_negative</span>(<span class="dv">1</span>), <span class="sc">-</span><span class="dv">1</span>)</span>
|
273 |
+
<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>
|
274 |
+
<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>
|
275 |
+
<div class="cell-output cell-output-stdout">
|
276 |
+
<pre><code>Test passed 😀</code></pre>
|
277 |
+
</div>
|
278 |
+
</div>
|
279 |
+
</section>
|
280 |
+
<section id="supported-by" class="level2" data-number="5.5">
|
281 |
+
<h2 data-number="5.5" class="anchored" data-anchor-id="supported-by"><span class="header-section-number">5.5</span> Supported by</h2>
|
282 |
+
<div class="quarto-figure quarto-figure-center">
|
283 |
+
<figure class="figure">
|
284 |
+
<p><a href="https://www.starcore.co"><img src="new_starcore_logo.png" class="img-fluid figure-img"></a></p>
|
285 |
+
<figcaption class="figure-caption">StarCore Analytics</figcaption>
|
286 |
+
</figure>
|
287 |
+
</div>
|
288 |
+
|
289 |
+
|
290 |
+
</section>
|
291 |
+
|
292 |
+
</main> <!-- /main -->
|
293 |
+
<script id="quarto-html-after-body" type="application/javascript">
|
294 |
+
window.document.addEventListener("DOMContentLoaded", function (event) {
|
295 |
+
const toggleBodyColorMode = (bsSheetEl) => {
|
296 |
+
const mode = bsSheetEl.getAttribute("data-mode");
|
297 |
+
const bodyEl = window.document.querySelector("body");
|
298 |
+
if (mode === "dark") {
|
299 |
+
bodyEl.classList.add("quarto-dark");
|
300 |
+
bodyEl.classList.remove("quarto-light");
|
301 |
+
} else {
|
302 |
+
bodyEl.classList.add("quarto-light");
|
303 |
+
bodyEl.classList.remove("quarto-dark");
|
304 |
+
}
|
305 |
+
}
|
306 |
+
const toggleBodyColorPrimary = () => {
|
307 |
+
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
|
308 |
+
if (bsSheetEl) {
|
309 |
+
toggleBodyColorMode(bsSheetEl);
|
310 |
+
}
|
311 |
+
}
|
312 |
+
toggleBodyColorPrimary();
|
313 |
+
const icon = "";
|
314 |
+
const anchorJS = new window.AnchorJS();
|
315 |
+
anchorJS.options = {
|
316 |
+
placement: 'right',
|
317 |
+
icon: icon
|
318 |
+
};
|
319 |
+
anchorJS.add('.anchored');
|
320 |
+
const isCodeAnnotation = (el) => {
|
321 |
+
for (const clz of el.classList) {
|
322 |
+
if (clz.startsWith('code-annotation-')) {
|
323 |
+
return true;
|
324 |
+
}
|
325 |
+
}
|
326 |
+
return false;
|
327 |
+
}
|
328 |
+
const clipboard = new window.ClipboardJS('.code-copy-button', {
|
329 |
+
text: function(trigger) {
|
330 |
+
const codeEl = trigger.previousElementSibling.cloneNode(true);
|
331 |
+
for (const childEl of codeEl.children) {
|
332 |
+
if (isCodeAnnotation(childEl)) {
|
333 |
+
childEl.remove();
|
334 |
+
}
|
335 |
+
}
|
336 |
+
return codeEl.innerText;
|
337 |
+
}
|
338 |
+
});
|
339 |
+
clipboard.on('success', function(e) {
|
340 |
+
// button target
|
341 |
+
const button = e.trigger;
|
342 |
+
// don't keep focus
|
343 |
+
button.blur();
|
344 |
+
// flash "checked"
|
345 |
+
button.classList.add('code-copy-button-checked');
|
346 |
+
var currentTitle = button.getAttribute("title");
|
347 |
+
button.setAttribute("title", "Copied!");
|
348 |
+
let tooltip;
|
349 |
+
if (window.bootstrap) {
|
350 |
+
button.setAttribute("data-bs-toggle", "tooltip");
|
351 |
+
button.setAttribute("data-bs-placement", "left");
|
352 |
+
button.setAttribute("data-bs-title", "Copied!");
|
353 |
+
tooltip = new bootstrap.Tooltip(button,
|
354 |
+
{ trigger: "manual",
|
355 |
+
customClass: "code-copy-button-tooltip",
|
356 |
+
offset: [0, -8]});
|
357 |
+
tooltip.show();
|
358 |
+
}
|
359 |
+
setTimeout(function() {
|
360 |
+
if (tooltip) {
|
361 |
+
tooltip.hide();
|
362 |
+
button.removeAttribute("data-bs-title");
|
363 |
+
button.removeAttribute("data-bs-toggle");
|
364 |
+
button.removeAttribute("data-bs-placement");
|
365 |
+
}
|
366 |
+
button.setAttribute("title", currentTitle);
|
367 |
+
button.classList.remove('code-copy-button-checked');
|
368 |
+
}, 1000);
|
369 |
+
// clear code selection
|
370 |
+
e.clearSelection();
|
371 |
+
});
|
372 |
+
function tippyHover(el, contentFn) {
|
373 |
+
const config = {
|
374 |
+
allowHTML: true,
|
375 |
+
content: contentFn,
|
376 |
+
maxWidth: 500,
|
377 |
+
delay: 100,
|
378 |
+
arrow: false,
|
379 |
+
appendTo: function(el) {
|
380 |
+
return el.parentElement;
|
381 |
+
},
|
382 |
+
interactive: true,
|
383 |
+
interactiveBorder: 10,
|
384 |
+
theme: 'quarto',
|
385 |
+
placement: 'bottom-start'
|
386 |
+
};
|
387 |
+
window.tippy(el, config);
|
388 |
+
}
|
389 |
+
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
|
390 |
+
for (var i=0; i<noterefs.length; i++) {
|
391 |
+
const ref = noterefs[i];
|
392 |
+
tippyHover(ref, function() {
|
393 |
+
// use id or data attribute instead here
|
394 |
+
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
|
395 |
+
try { href = new URL(href).hash; } catch {}
|
396 |
+
const id = href.replace(/^#\/?/, "");
|
397 |
+
const note = window.document.getElementById(id);
|
398 |
+
return note.innerHTML;
|
399 |
+
});
|
400 |
+
}
|
401 |
+
let selectedAnnoteEl;
|
402 |
+
const selectorForAnnotation = ( cell, annotation) => {
|
403 |
+
let cellAttr = 'data-code-cell="' + cell + '"';
|
404 |
+
let lineAttr = 'data-code-annotation="' + annotation + '"';
|
405 |
+
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
|
406 |
+
return selector;
|
407 |
+
}
|
408 |
+
const selectCodeLines = (annoteEl) => {
|
409 |
+
const doc = window.document;
|
410 |
+
const targetCell = annoteEl.getAttribute("data-target-cell");
|
411 |
+
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
|
412 |
+
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
|
413 |
+
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
|
414 |
+
const lineIds = lines.map((line) => {
|
415 |
+
return targetCell + "-" + line;
|
416 |
+
})
|
417 |
+
let top = null;
|
418 |
+
let height = null;
|
419 |
+
let parent = null;
|
420 |
+
if (lineIds.length > 0) {
|
421 |
+
//compute the position of the single el (top and bottom and make a div)
|
422 |
+
const el = window.document.getElementById(lineIds[0]);
|
423 |
+
top = el.offsetTop;
|
424 |
+
height = el.offsetHeight;
|
425 |
+
parent = el.parentElement.parentElement;
|
426 |
+
if (lineIds.length > 1) {
|
427 |
+
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
|
428 |
+
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
|
429 |
+
height = bottom - top;
|
430 |
+
}
|
431 |
+
if (top !== null && height !== null && parent !== null) {
|
432 |
+
// cook up a div (if necessary) and position it
|
433 |
+
let div = window.document.getElementById("code-annotation-line-highlight");
|
434 |
+
if (div === null) {
|
435 |
+
div = window.document.createElement("div");
|
436 |
+
div.setAttribute("id", "code-annotation-line-highlight");
|
437 |
+
div.style.position = 'absolute';
|
438 |
+
parent.appendChild(div);
|
439 |
+
}
|
440 |
+
div.style.top = top - 2 + "px";
|
441 |
+
div.style.height = height + 4 + "px";
|
442 |
+
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
|
443 |
+
if (gutterDiv === null) {
|
444 |
+
gutterDiv = window.document.createElement("div");
|
445 |
+
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
|
446 |
+
gutterDiv.style.position = 'absolute';
|
447 |
+
const codeCell = window.document.getElementById(targetCell);
|
448 |
+
const gutter = codeCell.querySelector('.code-annotation-gutter');
|
449 |
+
gutter.appendChild(gutterDiv);
|
450 |
+
}
|
451 |
+
gutterDiv.style.top = top - 2 + "px";
|
452 |
+
gutterDiv.style.height = height + 4 + "px";
|
453 |
+
}
|
454 |
+
selectedAnnoteEl = annoteEl;
|
455 |
+
}
|
456 |
+
};
|
457 |
+
const unselectCodeLines = () => {
|
458 |
+
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
|
459 |
+
elementsIds.forEach((elId) => {
|
460 |
+
const div = window.document.getElementById(elId);
|
461 |
+
if (div) {
|
462 |
+
div.remove();
|
463 |
+
}
|
464 |
+
});
|
465 |
+
selectedAnnoteEl = undefined;
|
466 |
+
};
|
467 |
+
// Attach click handler to the DT
|
468 |
+
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
|
469 |
+
for (const annoteDlNode of annoteDls) {
|
470 |
+
annoteDlNode.addEventListener('click', (event) => {
|
471 |
+
const clickedEl = event.target;
|
472 |
+
if (clickedEl !== selectedAnnoteEl) {
|
473 |
+
unselectCodeLines();
|
474 |
+
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
|
475 |
+
if (activeEl) {
|
476 |
+
activeEl.classList.remove('code-annotation-active');
|
477 |
+
}
|
478 |
+
selectCodeLines(clickedEl);
|
479 |
+
clickedEl.classList.add('code-annotation-active');
|
480 |
+
} else {
|
481 |
+
// Unselect the line
|
482 |
+
unselectCodeLines();
|
483 |
+
clickedEl.classList.remove('code-annotation-active');
|
484 |
+
}
|
485 |
+
});
|
486 |
+
}
|
487 |
+
const findCites = (el) => {
|
488 |
+
const parentEl = el.parentElement;
|
489 |
+
if (parentEl) {
|
490 |
+
const cites = parentEl.dataset.cites;
|
491 |
+
if (cites) {
|
492 |
+
return {
|
493 |
+
el,
|
494 |
+
cites: cites.split(' ')
|
495 |
+
};
|
496 |
+
} else {
|
497 |
+
return findCites(el.parentElement)
|
498 |
+
}
|
499 |
+
} else {
|
500 |
+
return undefined;
|
501 |
+
}
|
502 |
+
};
|
503 |
+
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
|
504 |
+
for (var i=0; i<bibliorefs.length; i++) {
|
505 |
+
const ref = bibliorefs[i];
|
506 |
+
const citeInfo = findCites(ref);
|
507 |
+
if (citeInfo) {
|
508 |
+
tippyHover(citeInfo.el, function() {
|
509 |
+
var popup = window.document.createElement('div');
|
510 |
+
citeInfo.cites.forEach(function(cite) {
|
511 |
+
var citeDiv = window.document.createElement('div');
|
512 |
+
citeDiv.classList.add('hanging-indent');
|
513 |
+
citeDiv.classList.add('csl-entry');
|
514 |
+
var biblioDiv = window.document.getElementById('ref-' + cite);
|
515 |
+
if (biblioDiv) {
|
516 |
+
citeDiv.innerHTML = biblioDiv.innerHTML;
|
517 |
+
}
|
518 |
+
popup.appendChild(citeDiv);
|
519 |
+
});
|
520 |
+
return popup.innerHTML;
|
521 |
+
});
|
522 |
+
}
|
523 |
+
}
|
524 |
+
});
|
525 |
+
</script>
|
526 |
+
<nav class="page-navigation">
|
527 |
+
<div class="nav-page nav-page-previous">
|
528 |
+
<a href="./cw004reducegrow.html" class="pagination-link">
|
529 |
+
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">4</span> <span class="chapter-title">Beginner - Reduce but Grow</span></span>
|
530 |
+
</a>
|
531 |
+
</div>
|
532 |
+
<div class="nav-page nav-page-next">
|
533 |
+
<a href="./cw006positive_sum.html" class="pagination-link">
|
534 |
+
<span class="nav-page-text"><span class="chapter-number">6</span> <span class="chapter-title">Sum of positive</span></span> <i class="bi bi-arrow-right-short"></i>
|
535 |
+
</a>
|
536 |
+
</div>
|
537 |
+
</nav>
|
538 |
+
</div> <!-- /content -->
|
539 |
+
|
540 |
+
|
541 |
+
|
542 |
+
</body></html>
|
cw006positive_sum.html
ADDED
@@ -0,0 +1,552 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 - 6 Sum of positive</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="./references.html" rel="next">
|
68 |
+
<link href="./cw005make_negative.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 - 6 Sum of positive">
|
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="./cw006positive_sum.html"><span class="chapter-number">6</span> <span class="chapter-title">Sum of positive</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> <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> <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> <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> <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> <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 active">
|
186 |
+
<span class="menu-text"><span class="chapter-number">6</span> <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="./references.html" class="sidebar-item-text sidebar-link">
|
192 |
+
<span class="menu-text">References</span></a>
|
193 |
+
</div>
|
194 |
+
</li>
|
195 |
+
</ul>
|
196 |
+
</div>
|
197 |
+
</nav>
|
198 |
+
<div id="quarto-sidebar-glass" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass"></div>
|
199 |
+
<!-- margin-sidebar -->
|
200 |
+
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
|
201 |
+
<nav id="TOC" role="doc-toc" class="toc-active">
|
202 |
+
<h2 id="toc-title">Table of contents</h2>
|
203 |
+
|
204 |
+
<ul>
|
205 |
+
<li><a href="#instruction" id="toc-instruction" class="nav-link active" data-scroll-target="#instruction"><span class="header-section-number">6.1</span> Instruction</a></li>
|
206 |
+
<li><a href="#youtube-video" id="toc-youtube-video" class="nav-link" data-scroll-target="#youtube-video"><span class="header-section-number">6.2</span> YouTube Video</a></li>
|
207 |
+
<li><a href="#solution-code" id="toc-solution-code" class="nav-link" data-scroll-target="#solution-code"><span class="header-section-number">6.3</span> Solution Code</a></li>
|
208 |
+
<li><a href="#test" id="toc-test" class="nav-link" data-scroll-target="#test"><span class="header-section-number">6.4</span> Test</a></li>
|
209 |
+
<li><a href="#supported-by" id="toc-supported-by" class="nav-link" data-scroll-target="#supported-by"><span class="header-section-number">6.5</span> Supported by</a></li>
|
210 |
+
</ul>
|
211 |
+
</nav>
|
212 |
+
</div>
|
213 |
+
<!-- main -->
|
214 |
+
<main class="content" id="quarto-document-content">
|
215 |
+
|
216 |
+
<header id="title-block-header" class="quarto-title-block default">
|
217 |
+
<div class="quarto-title">
|
218 |
+
<h1 class="title"><span class="chapter-number">6</span> <span class="chapter-title">Sum of positive</span></h1>
|
219 |
+
</div>
|
220 |
+
|
221 |
+
|
222 |
+
|
223 |
+
<div class="quarto-title-meta">
|
224 |
+
|
225 |
+
|
226 |
+
|
227 |
+
|
228 |
+
</div>
|
229 |
+
|
230 |
+
|
231 |
+
</header>
|
232 |
+
|
233 |
+
<p>Tantangan #6/366 - 19 Feb 2024</p>
|
234 |
+
<p><a href="https://www.codewars.com/kata/5715eaedb436cf5606000381/train/r" class="uri">https://www.codewars.com/kata/5715eaedb436cf5606000381/train/r</a></p>
|
235 |
+
<p><span class="badge rounded-pill quarto-badge " style="background-color: grey;">8kyu</span> Sum of positive</p>
|
236 |
+
<section id="instruction" class="level2" data-number="6.1">
|
237 |
+
<h2 data-number="6.1" class="anchored" data-anchor-id="instruction"><span class="header-section-number">6.1</span> Instruction</h2>
|
238 |
+
<p>You get an array of numbers, return the sum of all of the positives ones.</p>
|
239 |
+
<p>Example <code>[1,-4,7,12]</code> => <code>1 + 7 + 12 = 20</code></p>
|
240 |
+
<p>Note: if there is nothing to sum, the sum is default to 0.</p>
|
241 |
+
</section>
|
242 |
+
<section id="youtube-video" class="level2" data-number="6.2">
|
243 |
+
<h2 data-number="6.2" class="anchored" data-anchor-id="youtube-video"><span class="header-section-number">6.2</span> YouTube Video</h2>
|
244 |
+
<div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/xCvHwR52p4k?si=yoLfpHfcIBYk0j9c" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
|
245 |
+
</section>
|
246 |
+
<section id="solution-code" class="level2" data-number="6.3">
|
247 |
+
<h2 data-number="6.3" class="anchored" data-anchor-id="solution-code"><span class="header-section-number">6.3</span> Solution Code</h2>
|
248 |
+
<p>Solusi bar-bar</p>
|
249 |
+
<div class="cell">
|
250 |
+
<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>positive_sum <span class="ot"><-</span> <span class="cf">function</span>(vec){</span>
|
251 |
+
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> pos_vec <span class="ot"><-</span> <span class="fu">c</span>()</span>
|
252 |
+
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span>(i <span class="cf">in</span> vec){</span>
|
253 |
+
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span>(i <span class="sc">></span> <span class="dv">0</span>){</span>
|
254 |
+
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> pos_vec <span class="ot"><-</span> <span class="fu">c</span>(pos_vec, i)</span>
|
255 |
+
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> } <span class="cf">else</span> {</span>
|
256 |
+
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> pos_vec <span class="ot"><-</span> <span class="fu">c</span>(pos_vec, <span class="dv">0</span>)</span>
|
257 |
+
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> } </span>
|
258 |
+
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> }</span>
|
259 |
+
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="fu">sum</span>(pos_vec))</span>
|
260 |
+
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
261 |
+
</div>
|
262 |
+
<p>Solusi simple</p>
|
263 |
+
<div class="cell">
|
264 |
+
<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>positive_sum <span class="ot"><-</span> <span class="cf">function</span>(vec){</span>
|
265 |
+
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> vec[vec <span class="sc"><</span> <span class="dv">0</span>] <span class="ot"><-</span> <span class="dv">0</span></span>
|
266 |
+
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">sum</span>(vec)</span>
|
267 |
+
<span id="cb2-4"><a href="#cb2-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>
|
268 |
+
</div>
|
269 |
+
<div class="cell">
|
270 |
+
<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>positive_sum <span class="ot"><-</span> <span class="cf">function</span>(vec)<span class="fu">sum</span>(vec[vec<span class="sc">></span><span class="dv">0</span>])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
271 |
+
</div>
|
272 |
+
</section>
|
273 |
+
<section id="test" class="level2" data-number="6.4">
|
274 |
+
<h2 data-number="6.4" class="anchored" data-anchor-id="test"><span class="header-section-number">6.4</span> Test</h2>
|
275 |
+
<div class="cell">
|
276 |
+
<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>
|
277 |
+
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
|
278 |
+
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="fu">test_that</span>(<span class="st">'Basic tests'</span>, {</span>
|
279 |
+
<span id="cb4-4"><a href="#cb4-4" 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="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">4</span>,<span class="dv">5</span>)),<span class="dv">15</span>)</span>
|
280 |
+
<span id="cb4-5"><a href="#cb4-5" 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="dv">1</span>,<span class="sc">-</span><span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">4</span>,<span class="dv">5</span>)),<span class="dv">13</span>)</span>
|
281 |
+
<span id="cb4-6"><a href="#cb4-6" 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="dv">2</span>,<span class="dv">3</span>,<span class="dv">4</span>,<span class="sc">-</span><span class="dv">5</span>)),<span class="dv">9</span>)</span>
|
282 |
+
<span id="cb4-7"><a href="#cb4-7" 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="dv">0</span>)</span>
|
283 |
+
<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>
|
284 |
+
<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>
|
285 |
+
<div class="cell-output cell-output-stdout">
|
286 |
+
<pre><code>Test passed 😸</code></pre>
|
287 |
+
</div>
|
288 |
+
</div>
|
289 |
+
</section>
|
290 |
+
<section id="supported-by" class="level2" data-number="6.5">
|
291 |
+
<h2 data-number="6.5" class="anchored" data-anchor-id="supported-by"><span class="header-section-number">6.5</span> Supported by</h2>
|
292 |
+
<div class="quarto-figure quarto-figure-center">
|
293 |
+
<figure class="figure">
|
294 |
+
<p><a href="https://www.starcore.co"><img src="new_starcore_logo.png" class="img-fluid figure-img"></a></p>
|
295 |
+
<figcaption class="figure-caption">StarCore Analytics</figcaption>
|
296 |
+
</figure>
|
297 |
+
</div>
|
298 |
+
|
299 |
+
|
300 |
+
</section>
|
301 |
+
|
302 |
+
</main> <!-- /main -->
|
303 |
+
<script id="quarto-html-after-body" type="application/javascript">
|
304 |
+
window.document.addEventListener("DOMContentLoaded", function (event) {
|
305 |
+
const toggleBodyColorMode = (bsSheetEl) => {
|
306 |
+
const mode = bsSheetEl.getAttribute("data-mode");
|
307 |
+
const bodyEl = window.document.querySelector("body");
|
308 |
+
if (mode === "dark") {
|
309 |
+
bodyEl.classList.add("quarto-dark");
|
310 |
+
bodyEl.classList.remove("quarto-light");
|
311 |
+
} else {
|
312 |
+
bodyEl.classList.add("quarto-light");
|
313 |
+
bodyEl.classList.remove("quarto-dark");
|
314 |
+
}
|
315 |
+
}
|
316 |
+
const toggleBodyColorPrimary = () => {
|
317 |
+
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
|
318 |
+
if (bsSheetEl) {
|
319 |
+
toggleBodyColorMode(bsSheetEl);
|
320 |
+
}
|
321 |
+
}
|
322 |
+
toggleBodyColorPrimary();
|
323 |
+
const icon = "";
|
324 |
+
const anchorJS = new window.AnchorJS();
|
325 |
+
anchorJS.options = {
|
326 |
+
placement: 'right',
|
327 |
+
icon: icon
|
328 |
+
};
|
329 |
+
anchorJS.add('.anchored');
|
330 |
+
const isCodeAnnotation = (el) => {
|
331 |
+
for (const clz of el.classList) {
|
332 |
+
if (clz.startsWith('code-annotation-')) {
|
333 |
+
return true;
|
334 |
+
}
|
335 |
+
}
|
336 |
+
return false;
|
337 |
+
}
|
338 |
+
const clipboard = new window.ClipboardJS('.code-copy-button', {
|
339 |
+
text: function(trigger) {
|
340 |
+
const codeEl = trigger.previousElementSibling.cloneNode(true);
|
341 |
+
for (const childEl of codeEl.children) {
|
342 |
+
if (isCodeAnnotation(childEl)) {
|
343 |
+
childEl.remove();
|
344 |
+
}
|
345 |
+
}
|
346 |
+
return codeEl.innerText;
|
347 |
+
}
|
348 |
+
});
|
349 |
+
clipboard.on('success', function(e) {
|
350 |
+
// button target
|
351 |
+
const button = e.trigger;
|
352 |
+
// don't keep focus
|
353 |
+
button.blur();
|
354 |
+
// flash "checked"
|
355 |
+
button.classList.add('code-copy-button-checked');
|
356 |
+
var currentTitle = button.getAttribute("title");
|
357 |
+
button.setAttribute("title", "Copied!");
|
358 |
+
let tooltip;
|
359 |
+
if (window.bootstrap) {
|
360 |
+
button.setAttribute("data-bs-toggle", "tooltip");
|
361 |
+
button.setAttribute("data-bs-placement", "left");
|
362 |
+
button.setAttribute("data-bs-title", "Copied!");
|
363 |
+
tooltip = new bootstrap.Tooltip(button,
|
364 |
+
{ trigger: "manual",
|
365 |
+
customClass: "code-copy-button-tooltip",
|
366 |
+
offset: [0, -8]});
|
367 |
+
tooltip.show();
|
368 |
+
}
|
369 |
+
setTimeout(function() {
|
370 |
+
if (tooltip) {
|
371 |
+
tooltip.hide();
|
372 |
+
button.removeAttribute("data-bs-title");
|
373 |
+
button.removeAttribute("data-bs-toggle");
|
374 |
+
button.removeAttribute("data-bs-placement");
|
375 |
+
}
|
376 |
+
button.setAttribute("title", currentTitle);
|
377 |
+
button.classList.remove('code-copy-button-checked');
|
378 |
+
}, 1000);
|
379 |
+
// clear code selection
|
380 |
+
e.clearSelection();
|
381 |
+
});
|
382 |
+
function tippyHover(el, contentFn) {
|
383 |
+
const config = {
|
384 |
+
allowHTML: true,
|
385 |
+
content: contentFn,
|
386 |
+
maxWidth: 500,
|
387 |
+
delay: 100,
|
388 |
+
arrow: false,
|
389 |
+
appendTo: function(el) {
|
390 |
+
return el.parentElement;
|
391 |
+
},
|
392 |
+
interactive: true,
|
393 |
+
interactiveBorder: 10,
|
394 |
+
theme: 'quarto',
|
395 |
+
placement: 'bottom-start'
|
396 |
+
};
|
397 |
+
window.tippy(el, config);
|
398 |
+
}
|
399 |
+
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
|
400 |
+
for (var i=0; i<noterefs.length; i++) {
|
401 |
+
const ref = noterefs[i];
|
402 |
+
tippyHover(ref, function() {
|
403 |
+
// use id or data attribute instead here
|
404 |
+
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
|
405 |
+
try { href = new URL(href).hash; } catch {}
|
406 |
+
const id = href.replace(/^#\/?/, "");
|
407 |
+
const note = window.document.getElementById(id);
|
408 |
+
return note.innerHTML;
|
409 |
+
});
|
410 |
+
}
|
411 |
+
let selectedAnnoteEl;
|
412 |
+
const selectorForAnnotation = ( cell, annotation) => {
|
413 |
+
let cellAttr = 'data-code-cell="' + cell + '"';
|
414 |
+
let lineAttr = 'data-code-annotation="' + annotation + '"';
|
415 |
+
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
|
416 |
+
return selector;
|
417 |
+
}
|
418 |
+
const selectCodeLines = (annoteEl) => {
|
419 |
+
const doc = window.document;
|
420 |
+
const targetCell = annoteEl.getAttribute("data-target-cell");
|
421 |
+
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
|
422 |
+
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
|
423 |
+
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
|
424 |
+
const lineIds = lines.map((line) => {
|
425 |
+
return targetCell + "-" + line;
|
426 |
+
})
|
427 |
+
let top = null;
|
428 |
+
let height = null;
|
429 |
+
let parent = null;
|
430 |
+
if (lineIds.length > 0) {
|
431 |
+
//compute the position of the single el (top and bottom and make a div)
|
432 |
+
const el = window.document.getElementById(lineIds[0]);
|
433 |
+
top = el.offsetTop;
|
434 |
+
height = el.offsetHeight;
|
435 |
+
parent = el.parentElement.parentElement;
|
436 |
+
if (lineIds.length > 1) {
|
437 |
+
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
|
438 |
+
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
|
439 |
+
height = bottom - top;
|
440 |
+
}
|
441 |
+
if (top !== null && height !== null && parent !== null) {
|
442 |
+
// cook up a div (if necessary) and position it
|
443 |
+
let div = window.document.getElementById("code-annotation-line-highlight");
|
444 |
+
if (div === null) {
|
445 |
+
div = window.document.createElement("div");
|
446 |
+
div.setAttribute("id", "code-annotation-line-highlight");
|
447 |
+
div.style.position = 'absolute';
|
448 |
+
parent.appendChild(div);
|
449 |
+
}
|
450 |
+
div.style.top = top - 2 + "px";
|
451 |
+
div.style.height = height + 4 + "px";
|
452 |
+
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
|
453 |
+
if (gutterDiv === null) {
|
454 |
+
gutterDiv = window.document.createElement("div");
|
455 |
+
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
|
456 |
+
gutterDiv.style.position = 'absolute';
|
457 |
+
const codeCell = window.document.getElementById(targetCell);
|
458 |
+
const gutter = codeCell.querySelector('.code-annotation-gutter');
|
459 |
+
gutter.appendChild(gutterDiv);
|
460 |
+
}
|
461 |
+
gutterDiv.style.top = top - 2 + "px";
|
462 |
+
gutterDiv.style.height = height + 4 + "px";
|
463 |
+
}
|
464 |
+
selectedAnnoteEl = annoteEl;
|
465 |
+
}
|
466 |
+
};
|
467 |
+
const unselectCodeLines = () => {
|
468 |
+
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
|
469 |
+
elementsIds.forEach((elId) => {
|
470 |
+
const div = window.document.getElementById(elId);
|
471 |
+
if (div) {
|
472 |
+
div.remove();
|
473 |
+
}
|
474 |
+
});
|
475 |
+
selectedAnnoteEl = undefined;
|
476 |
+
};
|
477 |
+
// Attach click handler to the DT
|
478 |
+
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
|
479 |
+
for (const annoteDlNode of annoteDls) {
|
480 |
+
annoteDlNode.addEventListener('click', (event) => {
|
481 |
+
const clickedEl = event.target;
|
482 |
+
if (clickedEl !== selectedAnnoteEl) {
|
483 |
+
unselectCodeLines();
|
484 |
+
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
|
485 |
+
if (activeEl) {
|
486 |
+
activeEl.classList.remove('code-annotation-active');
|
487 |
+
}
|
488 |
+
selectCodeLines(clickedEl);
|
489 |
+
clickedEl.classList.add('code-annotation-active');
|
490 |
+
} else {
|
491 |
+
// Unselect the line
|
492 |
+
unselectCodeLines();
|
493 |
+
clickedEl.classList.remove('code-annotation-active');
|
494 |
+
}
|
495 |
+
});
|
496 |
+
}
|
497 |
+
const findCites = (el) => {
|
498 |
+
const parentEl = el.parentElement;
|
499 |
+
if (parentEl) {
|
500 |
+
const cites = parentEl.dataset.cites;
|
501 |
+
if (cites) {
|
502 |
+
return {
|
503 |
+
el,
|
504 |
+
cites: cites.split(' ')
|
505 |
+
};
|
506 |
+
} else {
|
507 |
+
return findCites(el.parentElement)
|
508 |
+
}
|
509 |
+
} else {
|
510 |
+
return undefined;
|
511 |
+
}
|
512 |
+
};
|
513 |
+
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
|
514 |
+
for (var i=0; i<bibliorefs.length; i++) {
|
515 |
+
const ref = bibliorefs[i];
|
516 |
+
const citeInfo = findCites(ref);
|
517 |
+
if (citeInfo) {
|
518 |
+
tippyHover(citeInfo.el, function() {
|
519 |
+
var popup = window.document.createElement('div');
|
520 |
+
citeInfo.cites.forEach(function(cite) {
|
521 |
+
var citeDiv = window.document.createElement('div');
|
522 |
+
citeDiv.classList.add('hanging-indent');
|
523 |
+
citeDiv.classList.add('csl-entry');
|
524 |
+
var biblioDiv = window.document.getElementById('ref-' + cite);
|
525 |
+
if (biblioDiv) {
|
526 |
+
citeDiv.innerHTML = biblioDiv.innerHTML;
|
527 |
+
}
|
528 |
+
popup.appendChild(citeDiv);
|
529 |
+
});
|
530 |
+
return popup.innerHTML;
|
531 |
+
});
|
532 |
+
}
|
533 |
+
}
|
534 |
+
});
|
535 |
+
</script>
|
536 |
+
<nav class="page-navigation">
|
537 |
+
<div class="nav-page nav-page-previous">
|
538 |
+
<a href="./cw005make_negative.html" class="pagination-link">
|
539 |
+
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">5</span> <span class="chapter-title">Return Negative</span></span>
|
540 |
+
</a>
|
541 |
+
</div>
|
542 |
+
<div class="nav-page nav-page-next">
|
543 |
+
<a href="./references.html" class="pagination-link">
|
544 |
+
<span class="nav-page-text">References</span> <i class="bi bi-arrow-right-short"></i>
|
545 |
+
</a>
|
546 |
+
</div>
|
547 |
+
</nav>
|
548 |
+
</div> <!-- /content -->
|
549 |
+
|
550 |
+
|
551 |
+
|
552 |
+
</body></html>
|
index.html
CHANGED
@@ -31,7 +31,8 @@ ul.task-list li input[type="checkbox"] {
|
|
31 |
<script src="site_libs/quarto-search/fuse.min.js"></script>
|
32 |
<script src="site_libs/quarto-search/quarto-search.js"></script>
|
33 |
<meta name="quarto:offset" content="./">
|
34 |
-
<link href="./
|
|
|
35 |
<script src="site_libs/quarto-html/quarto.js"></script>
|
36 |
<script src="site_libs/quarto-html/popper.min.js"></script>
|
37 |
<script src="site_libs/quarto-html/tippy.umd.min.js"></script>
|
@@ -63,6 +64,12 @@ ul.task-list li input[type="checkbox"] {
|
|
63 |
}</script>
|
64 |
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
</head>
|
67 |
|
68 |
<body class="nav-sidebar floating">
|
@@ -90,6 +97,9 @@ ul.task-list li input[type="checkbox"] {
|
|
90 |
<div class="pt-lg-2 mt-2 text-left sidebar-header">
|
91 |
<div class="sidebar-title mb-0 py-0">
|
92 |
<a href="./">Codewars Challenge 2024 Menggunakan R dan RStudio</a>
|
|
|
|
|
|
|
93 |
</div>
|
94 |
</div>
|
95 |
<div class="mt-2 flex-shrink-0 align-items-center">
|
@@ -107,37 +117,37 @@ ul.task-list li input[type="checkbox"] {
|
|
107 |
</li>
|
108 |
<li class="sidebar-item">
|
109 |
<div class="sidebar-item-container">
|
110 |
-
<a href="./
|
111 |
<span class="menu-text"><span class="chapter-number">1</span> <span class="chapter-title">Even or Odd</span></span></a>
|
112 |
</div>
|
113 |
</li>
|
114 |
<li class="sidebar-item">
|
115 |
<div class="sidebar-item-container">
|
116 |
-
<a href="./
|
117 |
<span class="menu-text"><span class="chapter-number">2</span> <span class="chapter-title">Multiply</span></span></a>
|
118 |
</div>
|
119 |
</li>
|
120 |
<li class="sidebar-item">
|
121 |
<div class="sidebar-item-container">
|
122 |
-
<a href="./
|
123 |
<span class="menu-text"><span class="chapter-number">3</span> <span class="chapter-title">If you can’t sleep, just count sheep!!</span></span></a>
|
124 |
</div>
|
125 |
</li>
|
126 |
<li class="sidebar-item">
|
127 |
<div class="sidebar-item-container">
|
128 |
-
<a href="./
|
129 |
<span class="menu-text"><span class="chapter-number">4</span> <span class="chapter-title">Beginner - Reduce but Grow</span></span></a>
|
130 |
</div>
|
131 |
</li>
|
132 |
<li class="sidebar-item">
|
133 |
<div class="sidebar-item-container">
|
134 |
-
<a href="./
|
135 |
<span class="menu-text"><span class="chapter-number">5</span> <span class="chapter-title">Return Negative</span></span></a>
|
136 |
</div>
|
137 |
</li>
|
138 |
<li class="sidebar-item">
|
139 |
<div class="sidebar-item-container">
|
140 |
-
<a href="./
|
141 |
<span class="menu-text"><span class="chapter-number">6</span> <span class="chapter-title">Sum of positive</span></span></a>
|
142 |
</div>
|
143 |
</li>
|
@@ -451,7 +461,7 @@ window.document.addEventListener("DOMContentLoaded", function (event) {
|
|
451 |
<div class="nav-page nav-page-previous">
|
452 |
</div>
|
453 |
<div class="nav-page nav-page-next">
|
454 |
-
<a href="./
|
455 |
<span class="nav-page-text"><span class="chapter-number">1</span> <span class="chapter-title">Even or Odd</span></span> <i class="bi bi-arrow-right-short"></i>
|
456 |
</a>
|
457 |
</div>
|
|
|
31 |
<script src="site_libs/quarto-search/fuse.min.js"></script>
|
32 |
<script src="site_libs/quarto-search/quarto-search.js"></script>
|
33 |
<meta name="quarto:offset" content="./">
|
34 |
+
<link href="./cw001evenodd.html" rel="next">
|
35 |
+
<link href="./logo.png" rel="icon" type="image/png">
|
36 |
<script src="site_libs/quarto-html/quarto.js"></script>
|
37 |
<script src="site_libs/quarto-html/popper.min.js"></script>
|
38 |
<script src="site_libs/quarto-html/tippy.umd.min.js"></script>
|
|
|
64 |
}</script>
|
65 |
|
66 |
|
67 |
+
<meta name="twitter:title" content="Codewars Challenge 2024 Menggunakan R dan RStudio">
|
68 |
+
<meta name="twitter:description" content="">
|
69 |
+
<meta name="twitter:image" content="https://huggingface.co/spaces/aephidayatuloh/codewars2024/new_starcore_logo.png">
|
70 |
+
<meta name="twitter:image-height" content="434">
|
71 |
+
<meta name="twitter:image-width" content="1946">
|
72 |
+
<meta name="twitter:card" content="summary_large_image">
|
73 |
</head>
|
74 |
|
75 |
<body class="nav-sidebar floating">
|
|
|
97 |
<div class="pt-lg-2 mt-2 text-left sidebar-header">
|
98 |
<div class="sidebar-title mb-0 py-0">
|
99 |
<a href="./">Codewars Challenge 2024 Menggunakan R dan RStudio</a>
|
100 |
+
<div class="sidebar-tools-main">
|
101 |
+
<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>
|
102 |
+
</div>
|
103 |
</div>
|
104 |
</div>
|
105 |
<div class="mt-2 flex-shrink-0 align-items-center">
|
|
|
117 |
</li>
|
118 |
<li class="sidebar-item">
|
119 |
<div class="sidebar-item-container">
|
120 |
+
<a href="./cw001evenodd.html" class="sidebar-item-text sidebar-link">
|
121 |
<span class="menu-text"><span class="chapter-number">1</span> <span class="chapter-title">Even or Odd</span></span></a>
|
122 |
</div>
|
123 |
</li>
|
124 |
<li class="sidebar-item">
|
125 |
<div class="sidebar-item-container">
|
126 |
+
<a href="./cw002multiply.html" class="sidebar-item-text sidebar-link">
|
127 |
<span class="menu-text"><span class="chapter-number">2</span> <span class="chapter-title">Multiply</span></span></a>
|
128 |
</div>
|
129 |
</li>
|
130 |
<li class="sidebar-item">
|
131 |
<div class="sidebar-item-container">
|
132 |
+
<a href="./cw003countsheep.html" class="sidebar-item-text sidebar-link">
|
133 |
<span class="menu-text"><span class="chapter-number">3</span> <span class="chapter-title">If you can’t sleep, just count sheep!!</span></span></a>
|
134 |
</div>
|
135 |
</li>
|
136 |
<li class="sidebar-item">
|
137 |
<div class="sidebar-item-container">
|
138 |
+
<a href="./cw004reducegrow.html" class="sidebar-item-text sidebar-link">
|
139 |
<span class="menu-text"><span class="chapter-number">4</span> <span class="chapter-title">Beginner - Reduce but Grow</span></span></a>
|
140 |
</div>
|
141 |
</li>
|
142 |
<li class="sidebar-item">
|
143 |
<div class="sidebar-item-container">
|
144 |
+
<a href="./cw005make_negative.html" class="sidebar-item-text sidebar-link">
|
145 |
<span class="menu-text"><span class="chapter-number">5</span> <span class="chapter-title">Return Negative</span></span></a>
|
146 |
</div>
|
147 |
</li>
|
148 |
<li class="sidebar-item">
|
149 |
<div class="sidebar-item-container">
|
150 |
+
<a href="./cw006positive_sum.html" class="sidebar-item-text sidebar-link">
|
151 |
<span class="menu-text"><span class="chapter-number">6</span> <span class="chapter-title">Sum of positive</span></span></a>
|
152 |
</div>
|
153 |
</li>
|
|
|
461 |
<div class="nav-page nav-page-previous">
|
462 |
</div>
|
463 |
<div class="nav-page nav-page-next">
|
464 |
+
<a href="./cw001evenodd.html" class="pagination-link">
|
465 |
<span class="nav-page-text"><span class="chapter-number">1</span> <span class="chapter-title">Even or Odd</span></span> <i class="bi bi-arrow-right-short"></i>
|
466 |
</a>
|
467 |
</div>
|