My Coding Quiz #56

My Coding Quiz #56 👨‍💻🛠️🧩

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...




Quiz
By @eniolw


What's your choice?

Solution to the previous quiz: c5 As usual, let's look at the script line by line. Line 1 declares a variable zz with the string 'Nf6'. If you know chess and have followed this series before, you will probably recognise that it describes a chess move in algebraic notation. The same is true for the game list in line 2.

Line 3 creates a new moves list from the game list and the variable zz. This list consists of [ 'Nf3', 'c5', 'c4', 'Nf6' ].

The interesting thing, however, occurs in line 4: const one = moves.reduce((a, b) => a > b ? a : b). We have created a variable one by applying the built-in reduce method, which produces a single value from the values of a given iterable, which in our case is moves. The function that reduce receives is the one that does the trick. In our case, the function (a, b) => a > b ? a : b selects the largest value (the ternary operator says it all).

Therefore, reduce will get the largest value in the moves list, which is c5. Why c5? Well, we are doing lexicographic comparison. Let's look at the contents of moves again: [ 'Nf3', 'c5', 'c4', 'Nf6' ]. Upper case letters have a lower ordinal value than lower case letters, so they are considered lower. That eliminates Nf3 and Nf6. We are left with c5 and c4, and here it is easy to tell that c5 is greater by comparing the second character of both strings.


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 and others.


Mi Quiz de Programación #56 👨‍💻🛠️🧩

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...




Quiz
Por @eniolw


¿Cuál es tu elección?

Solución al quiz anterior: c5. Como de costumbre, veamos el script línea por línea. La línea 1 declara una variable zz con la cadena 'Nf6'. Si sabes ajedrez y has seguido esta serie antes, probablemente reconocerás que describe una jugada de ajedrez en notación algebraica. Lo mismo ocurre con la lista game en la línea 2.

La línea 3 crea una nueva lista de moves a partir de la lista de game y la variable zz. Esta lista consta de [ 'Nf3', 'c5', 'c4', 'Nf6' ].

Lo interesante, sin embargo, ocurre en la línea 4: const one = moves.reduce((a, b) => a > b ? a : b). Hemos creado una variable one aplicando el método incorporado reduce, que produce un valor único a partir de los valores de un iterable dado, que en nuestro caso es moves. La función que recibe reduce es la que hace el truco. En nuestro caso, la función (a, b) => a > b ? a : b selecciona el valor más grande (el operador ternario lo dice todo).

Por lo tanto, reduce obtendrá el valor más grande en la lista de moves, que es c5. ¿Por qué c5? Bueno, estamos haciendo una comparación lexicográfica. Veamos de nuevo el contenido de las moves: [ 'Nf3', 'c5', 'c4', 'Nf6' ]. Las letras mayúsculas tienen un valor ordinal más bajo que las minúsculas, por lo que se consideran inferiores. Eso elimina Nf3 y Nf6. Nos quedamos con c5 y c4, y aquí es fácil saber que c5 es mayor comparando el segundo carácter de ambas cadenas.


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.



0
0
0.000
4 comments
avatar

Congratulations @eniolw! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You have been a buzzy bee and published a post every day of the week.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

0
0
0.000
avatar

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. 
 

0
0
0.000