-
Play With The Garland And Understand How Array.sort() Works
Hello, checkiomates🐱👤!
We try to actively develop our presence in popular social networks and will never get tired of reminding you and inviting to our pages at Instagram and Twitter!
This week we all try to understand better how comparator function in Array.sort() works and light up a minimum number of bulbs on garland!
💡TIP
On Easy difficulty, each of the few starting stations is dedicated to a distinct data type. If you want to discover all CheckiO features, visit our tutorial. It's a longread, but it's worth it!
🏁MISSION
Garland by freeman_lex -
You are given a sequence lights, where each integer is a distinct light with its brightness. This value determines how many adjacent positions to both left and right the illumination from that light reaches, in addition to illuminating the position of that light itself. (A light whose brightness is zero will therefore illuminate only itself, but doesn’t have anything to shine on its neighbors).
Your task is to turn on as few individual lights as possible so that every position of the entire row is illuminated by at least one light. Since the smallest working subset of lights is not necessarily unique, your function should only return the number of lights needed to illuminate the entire row.
assert.strictEqual(illuminateAll([0, 0]), 2); assert.strictEqual(illuminateAll([2, 3, 3, 2]), 1); assert.strictEqual(illuminateAll([1, 0, 1, 0]), 2);
📖ARTICLE
Finally Understanding How Array.sort(comparator) Works - Try this personal way to remember how the comparator function in Array.sort() works.
👩💻CODE SHOT
This one is easy-peasy for you! How do you think, what the following code does?
function backwardString(value: string): string { return value.split('').reverse().join(''); }
🙌 Thanks for your attention! Hope to meet you at CheckiO. We are really interested in your thoughts! Please, leave a comment below! ⤵
Welcome to CheckiO - games for coders where you can improve your codings skills.
The main idea behind these games is to give you the opportunity to learn by exchanging experience with the rest of the community. Every day we are trying to find interesting solutions for you to help you become a better coder.
Join the Game