• Can You Cut Into Squares Using Random Numbers And Regex, Hah?

Hello, checkiomates🐱‍👤!

Try our new mission about number of cuttings needed and read arcticles about history and perspectives of regex, issues and obstacles in JS learning and generating truly random numbers.

💡TIP

We allow users to assign hotkeys to "Run Code", "Check Solution" and stop code. You may see current combinations on buttons and change them in editor menu. If you want to discover all CheckiO features, visit our tutorial. It's a longread, but it's worth it!

🏁MISSION

Cut Into Squares by freeman_lex -

You are given a rectangle, which is defined by its width w and height h, both positive integers. We allow a rectangle to be cut into two smaller rectangles with either a straight horizontal or a straight vertical cut at any integer position. The resulting smaller pieces can then be further cut into smaller pieces, as long as the length of the side being cut is at least two to allow a cut. Your task is to keep cutting the given rectangle into smaller pieces until each piece is a square, that is, the width of each piece equals its own height. This is always possible, since you could just keep cutting until the size of each piece has become 1-by-1. However, this function should return the smallest number of cuts that makes each piece a square.

assert.strictEqual(cutIntoSquares(4, 4), 0);
assert.strictEqual(cutIntoSquares(4, 2), 1);
assert.strictEqual(cutIntoSquares(7, 6), 4);

📖ARTICLE

A Complete Guide to Beginning with JavaScript -

This guide is not itself the means to learn JavaScript. This guide addresses issues around getting started (obstacles, preliminary knowledge, etc.) and then points you to curated resources to start learning. Consider this material a prologue or an introduction to the learning process itself so, you have the needed background and context before beginning the learning process.

Generating Unique Random Numbers In JavaScript Using Sets -

Want to create more randomized effects in your JavaScript code? The Math.random() method alone, with its limitations, won’t cut it for generating unique random numbers. Amejimaobari Ollornwi explains how to generate a series of unique random numbers using the Set object, how to use these random numbers as indexes for arrays, and explores some practical applications of randomization.

The History And Future Of Regular Expressions -

Although JavaScript regexes used to be underpowered compared to other modern flavors, numerous improvements in recent years mean that’s no longer true. Steven Levithan evaluates the history and present state of regular expressions in JavaScript with tips to make your regexes more readable, maintainable, and resilient.

👩‍💻CODE SHOT

It's a very simple task! Dont be shy) How do you think, what the following code does?

function ????????(text: string): string {
    return text
        .split(/\b/)
        .map(x => [...x]
            .reverse()
            .join('')
        ).join('');
}

🙌 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! ⤵

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