create account

My Coding Quiz #36 by eniolw

View this thread on: hive.blogpeakd.comecency.com
· @eniolw ·
$9.46
My Coding Quiz #36
<div class="text-justify">

<center><h2>My Coding Quiz #36 馃懆鈥嶐煉火煕狅笍馃З</h2></center>

<p>Welcome to the new installment of my series of <b>Coding Quizzes</b>, in which you will be able to test your knowledge and skills about programming and software development in a simple and fun way. If you want to learn more about it visit <a href="/@eniolw">my blog</a> here on Hive and the <a href="/@eniolw/my-coding-quiz-1">first post</a> where I introduced it.</p>

<h3>Without further ado, here's the riddle...</h3>

<br>
<center>
<img src="https://images.ecency.com/DQmefkq7pVWeC6CC8i6q53SRXnN3omGpwgMTBKjfuQjctpx/quiz_img_en.png)" alt="Quiz">
<h6>By @eniolw</h6>
</center>

<br><center><h3>What's your choice?</h3></center>

<p><b>Solution to the <a href="/@eniolw/my-coding-quiz-35">previous quiz</a>:</b> <b>false</b>. This script is similar to how curation works in blogging sites like Hive.</p>

<p>We see that three constant variables <code>vote</code>, <code>str</code> and <code>comment</code> are created. The variable <code>str</code> is an auxiliary that contains a string data. It is used shortly after to create the <code>comment</code> variable. However, when we try to parse its content we discover that the value of <code>str</code> does not follow the JSON format. The problem is that it uses single quotes (<code>''</code>) instead of double quotes (<code>""</code>). Did you notice this? If you didn't, you must have been suspicious of the fact that a <code>try-catch</code> clause was used. As a consequence <code>comment</code> is <b>undefined</b>.</p>

<p>Then we create the <code>flags</code> object with the <code>upvoted</code> and <code>commented</code> fields. We see that we use the negation operator twice (<code>!!</code>), which helps to get the truth value of <code>vote</code> and <code>comment</code>, whether truthy or falsy. We do this because we are only interested in the boolean value, not the complete data.</p>

<p>Finally, we create the constant variable <code>curated</code> using the expression <code>Object.values(flags).every(v => !!v)</code>. The static method <code>Object.values()</code> allows you to create an array from the values of a given object. This is incredibly useful if you want to iterate over the contents of an object using <code>for</code> or <code>map</code>, etc. In our script the array created is <b>[ true, false ]</b> because <code>comment</code> is <b>undefined</b> and this is a falsy value.</p>

<p>Then the <code>every</code> method receives the iterable implicitly and the callback function <code>v => !!v</code>. The <code>every</code> method checks if all the elements of the array satisfy the given condition. In our case, the array <b>[ true, false ]</b> does not, because the second item is false. As a consequence <code>every</code> returns <b>false</b> and is assigned to <code>curated</code>. The output is therefore <b>false</b>, indicating that the curation has not been completed.</p>

<hr>

<p>If you want to blog about computer science and programming content, I invite you to join <a href="/">Hive</a> and participate in its communities, such as <a href="/created/hive-196387">STEM-social</a>, <a href="/created/hive-154226">Develop Spanish</a>, <a href="/created/hive-169321">Programming & Dev</a>  others.</p>

<hr>

<center><h2>Mi Quiz de Programaci贸n #36 馃懆鈥嶐煉火煕狅笍馃З</h2></center>

<p>Bienvenido a mi nueva serie de <b>Quizzes de Programaci贸n</b>, en la cual podr谩s poner a prueba tus conocimientos y habilidades sobre programaci贸n y desarrollo de software de una manera sencilla y divertida.  Si quieres aprender m谩s sobre ella visita <a href="/@eniolw">mi blog</a> aqu铆 en Hive y el <a href="/@eniolw/my-coding-quiz-1">primer post</a> donde la present茅.</p>

<h3>Sin m谩s pre谩mbulos, he aqu铆 el acertijo...</h3>

<br>
<center>
<img src="https://images.ecency.com/DQmNRnt2fL1zjmCer2zJsDCyW8mTVvm4R3wjA8D6tLhnEgk/quiz_img_es.png" alt="Quiz">
<h6>Por @eniolw</h6>
</center>

<br><center><h3>驴Cu谩l es tu elecci贸n?</h3></center>

<p><b>Soluci贸n al <a href="/@eniolw/my-coding-quiz-35">quiz anterior</a>:</b> <b>false</b>. Este script es similar a c贸mo funciona la curaci贸n en sitios de blogs como Hive.</p>

<p>Vemos que se crean tres variables constantes <code>vote</code>, <code>str</code> y <code>comment</code>. La variable <code>str</code> es un auxiliar que contiene una cadena de datos. Se utiliza poco despu茅s para crear la variable <code>comment</code>. Sin embargo, cuando intentamos analizar su contenido descubrimos que el valor de <code>str</code> no sigue el formato JSON. El problema es que utiliza comillas simples (<code>''</code>) en lugar de comillas dobles (<code>""</code>). 驴Notaste esto? Si no lo hiciste, debiste haber sospechado del hecho de que se utiliz贸 una cl谩usula <code>try-catch</code>. Como consecuencia, <code>comment</code> es <b>undefined</b>.</p>

<p>Luego creamos el objeto <code>flags</code> con los campos <code>upvoted</code> y <code>commented</code>. Vemos que usamos el operador negaci贸n dos veces (<code>!!</code>), que ayuda a obtener el valor de verdad de <code>vote</code> y <code>comment</code>, ya sea truthy o falsy. Hacemos esto porque solo nos interesa el valor booleano, no los datos completos.</p>

<p>Finalmente, creamos la variable constante <code>curated</code> usando la expresi贸n <code>Object.values(flags).every(v => !!v)</code>. El m茅todo est谩tico <code>Object.values()</code> permite crear un arreglo a partir de los valores de un objeto determinado. Esto es incre铆blemente 煤til si deseas iterar sobre el contenido de un objeto usando <code>for</code> o <code>map</code>, etc. En nuestro script, el arreglo creado es <b>[ true, false ]</b> porque <code>comentario</code> es <b>undefined</b> y este es un valor falsy.</p>

<p>Entonces el m茅todo <code>every</code> recibe el iterable impl铆citamente y la funci贸n callback <code>v => !!v</code>. El m茅todo <code>every</code> comprueba si todos los elementos del arreglo satisfacen la condici贸n dada. En nuestro caso, el arreglo <b>[ true, false ]</b> no es as铆, porque el segundo elemento es falso. Como consecuencia, <code>every</code> devuelve <b>false</b> y se asigna a <code>curated</code>. Por lo tanto, el resultado es <b>false</b>, lo que indica que la curaci贸n no se ha completado.</p>

</p>

<hr>

<p>Si quieres bloguear sobre contenido inform谩tico y de programaci贸n, te invito a unirte a <a href="/">Hive</a> y participar en sus comunidades, tales como <a href="/created/hive-196387">STEM-social</a>, <a href="/created/hive-154226">Develop Spanish</a>, <a href="/created/hive-169321">Programming & Dev</a> y otras.</p>

</div>
馃憤  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 490 others
properties (23)
authoreniolw
permlinkmy-coding-quiz-36
categoryhive-169321
json_metadata"{"image":["https://images.ecency.com/DQmefkq7pVWeC6CC8i6q53SRXnN3omGpwgMTBKjfuQjctpx/quiz_img_en.png","https://images.ecency.com/DQmNRnt2fL1zjmCer2zJsDCyW8mTVvm4R3wjA8D6tLhnEgk/quiz_img_es.png"],"tags":["hive-169321","coding","programming","python","quiz","neoxian","proofofbrain","waivio","creaivecoin","spanish"],"description":"My Coding Quiz #36 Welcome to the new installment of my series of Coding Quizzes, in which you will be able to test your knowledge and skills about programming and software development in a fun way.","app":"ecency/3.0.37-vision","format":"markdown+html","image_ratios":["0.9597","0.9597"]}"
created2023-11-25 20:25:24
last_update2023-11-25 20:25:24
depth0
children1
last_payout2023-12-02 20:25:24
cashout_time1969-12-31 23:59:59
total_payout_value4.782 HBD
curator_payout_value4.680 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,619
author_reputation255,376,104,439,756
root_title"My Coding Quiz #36"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id129,165,539
net_rshares19,978,265,411,267
author_curate_reward""
vote details (554)
@stemsocial ·
re-eniolw-my-coding-quiz-36-20231127t004909160z
<div class='text-justify'> <div class='pull-left'>
 <img src='https://stem.openhive.network/images/stemsocialsupport7.png'> </div>

Thanks for your contribution to the <a href='/trending/hive-196387'>STEMsocial community</a>. Feel free to join us on <a href='https://discord.gg/9c7pKVD'>discord</a> to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.&nbsp;<br />&nbsp;<br />
</div>
properties (22)
authorstemsocial
permlinkre-eniolw-my-coding-quiz-36-20231127t004909160z
categoryhive-169321
json_metadata{"app":"STEMsocial"}
created2023-11-27 00:49:09
last_update2023-11-27 00:49:09
depth1
children0
last_payout2023-12-04 00:49:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length565
author_reputation22,918,491,691,707
root_title"My Coding Quiz #36"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id129,196,157
net_rshares0