
Hello, checkiomates🐱👤!
We unlock the expressive power of spread and rest patterns, explore the elegant algorithm known as reservoir sampling, and delve into the nuances of stringification and how JavaScript converts various types to strings. To cap things off, we present a unique sorting mission that challenges you to implement a custom comparison logic for positive integers based on the frequency of digits, creating a truly "wacky" order.
💡TIP
At your profile, after clicking on big percent number of your progress, you may see module and methods you have already used in your shared solutions. If you want to discover all CheckiO features, visit our tutorial. It's a longread, but it's worth it!
🏁MISSION
Ordinary Cardinals by freeman_lex -
Sorting can be performed meaningfully according to arbitrary comparison criteria, as long as those criteria satisfy the mathematical requirements of a total ordering relation. To play around with this concept to grok it, let us define a wacky ordering relation of positive integers so that for any two integers, the one that contains the digit 9 more times is considered to be larger, regardless of the magnitude and other digits of these numbers. For example, 99 > 123456789 > 1010 in this ordering. If both integers contain the digit 9 the same number of times, the comparison proceeds to the next lower digit 8, and so on down there until the first distinguishing digit has been discovered. If both integers contain every digit from 9 to 0 pairwise the same number of times, the ordinary integer order comparison determines their mutual ordering. Your goal is to sort given sequence of integers according to this rule in ascending order.
assert.deepStrictEqual( sortDigitCount([99, 123456789, 10000000000]), [10000000000, 123456789, 99] ); assert.deepStrictEqual( sortDigitCount([9876, 19, 4321, 99, 73, 241, 111111, 563, 33]), [111111, 33, 241, 4321, 563, 73, 19, 9876, 99] );
📖ARTICLES
The power of the spread and rest syntax in JavaScript -
Say hello to the spread syntax and rest parameter, two simple but powerful features that have helped me make JavaScript cleaner, more expressive, and less error-prone.
Reservoir sampling is a technique for selecting a fair random sample when you don't know the size of the set you're sampling from.
Converting values to strings in JavaScript has pitfalls -
When Dr. Axel says “converting values to strings in JavaScript is more complicated than it might seem”, I’m inclined to believe him. An interesting poke about into something seemingly simple you might not think about very much.
👩💻CODE SHOT
What do you think the following code does?
function ??????(data: number[]): number { const unsorted = data.slice(); return data.sort().reduce((sum,el,i) => sum += (el!= unsorted[i]) ? 1 : 0,0); }
🙌 Thanks for your attention! Hope to meet you at CheckiO, as well as at our Instagram and Twitter! We are really interested in your thoughts! Please, leave a comment below! ⤵