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 simple and fun way. If you want to learn more about it visit my blog here on Hive and the first post where I introduced it.
Without further ado, here's the riddle...
)
By @eniolw
What's your choice?
Solution to the previous quiz: false. This script is similar to how curation works in blogging sites like Hive.
We see that three constant variables vote
, str
and comment
are created. The variable str
is an auxiliary that contains a string data. It is used shortly after to create the comment
variable. However, when we try to parse its content we discover that the value of str
does not follow the JSON format. The problem is that it uses single quotes (''
) instead of double quotes (""
). Did you notice this? If you didn't, you must have been suspicious of the fact that a try-catch
clause was used. As a consequence comment
is undefined.
Then we create the flags
object with the upvoted
and commented
fields. We see that we use the negation operator twice (!!
), which helps to get the truth value of vote
and comment
, whether truthy or falsy. We do this because we are only interested in the boolean value, not the complete data.
Finally, we create the constant variable curated
using the expression Object.values(flags).every(v => !!v)
. The static method Object.values()
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 for
or map
, etc. In our script the array created is [ true, false ] because comment
is undefined and this is a falsy value.
Then the every
method receives the iterable implicitly and the callback function v => !!v
. The every
method checks if all the elements of the array satisfy the given condition. In our case, the array [ true, false ] does not, because the second item is false. As a consequence every
returns false and is assigned to curated
. The output is therefore false, indicating that the curation has not been completed.
If you want to blog about computer science and programming content, I invite you to join Hive and participate in its communities, such as STEM-social, Develop Spanish, Programming & Dev others.
Mi Quiz de Programaci贸n #36 馃懆鈥嶐煉火煕狅笍馃З
Bienvenido a mi nueva serie de Quizzes de Programaci贸n, 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 mi blog aqu铆 en Hive y el primer post donde la present茅.
Sin m谩s pre谩mbulos, he aqu铆 el acertijo...

Por @eniolw
驴Cu谩l es tu elecci贸n?
Soluci贸n al quiz anterior: false. Este script es similar a c贸mo funciona la curaci贸n en sitios de blogs como Hive.
Vemos que se crean tres variables constantes vote
, str
y comment
. La variable str
es un auxiliar que contiene una cadena de datos. Se utiliza poco despu茅s para crear la variable comment
. Sin embargo, cuando intentamos analizar su contenido descubrimos que el valor de str
no sigue el formato JSON. El problema es que utiliza comillas simples (''
) en lugar de comillas dobles (""
). 驴Notaste esto? Si no lo hiciste, debiste haber sospechado del hecho de que se utiliz贸 una cl谩usula try-catch
. Como consecuencia, comment
es undefined.
Luego creamos el objeto flags
con los campos upvoted
y commented
. Vemos que usamos el operador negaci贸n dos veces (!!
), que ayuda a obtener el valor de verdad de vote
y comment
, ya sea truthy o falsy. Hacemos esto porque solo nos interesa el valor booleano, no los datos completos.
Finalmente, creamos la variable constante curated
usando la expresi贸n Object.values(flags).every(v => !!v)
. El m茅todo est谩tico Object.values()
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 for
o map
, etc. En nuestro script, el arreglo creado es [ true, false ] porque comentario
es undefined y este es un valor falsy.
Entonces el m茅todo every
recibe el iterable impl铆citamente y la funci贸n callback v => !!v
. El m茅todo every
comprueba si todos los elementos del arreglo satisfacen la condici贸n dada. En nuestro caso, el arreglo [ true, false ] no es as铆, porque el segundo elemento es falso. Como consecuencia, every
devuelve false y se asigna a curated
. Por lo tanto, el resultado es false, lo que indica que la curaci贸n no se ha completado.
Si quieres bloguear sobre contenido inform谩tico y de programaci贸n, te invito a unirte a Hive y participar en sus comunidades, tales como STEM-social, Develop Spanish, Programming & Dev y otras.
Comments (1)
Thanks for your contribution to the STEMsocial community. Feel free to join us on discord 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.