The main objective of these exercises is practicing how to learn from code, to be given source code you don't understand and to study it until you could write it yourself. Keep these three words in mind as you complete your write-ups:
There are many strategies for creating the same behavior, and there are many ways to implement the same strategy.
By studying multiple solutions to the same challenge written by more experienced programmers, you will learn how to approach and solve coding challenges on your own.
You will need NPM and nvm on your computer to study this material
git clone [email protected]:HackYourFutureBelgium/solution-write-ups.git
(SSH)cd
into the repository
cd solution-write-ups
npm install
Using a browser with good DevTools will make your life easier: Chromium, FireFox, Edge, Chrome
study-lenses
package globally
npm install -g study-lenses
(if you do not have it already)npm update -g study-lenses
(if you already have it installed)study
command from your CLI
study
.test.js
file does not work, you can manually check on tests from
the config optionsIf you have a windows computer and get this error:
... /study.ps1 cannot be loaded because running scripts ...
follow the instructions in this StackOverflow answer, that should take care of it ; )
The debugger built into VSCode is very good, it's all you'll need. Don't forget to set breakpoints!
.js
(without .test
):
Current JS File (no tests)
option, and click the
triangle button. (hint you will need to use breakpoints)node path/to/file.js
, simple and easy.test.js
or .spec.js
:
Current JS File (with tests)
option, and click the
triangle button. (hint: you will need to use breakpoints)npm run test -- path/to/file.test.js
.Normally people log into these platforms to solve challenges and progress through the ranks. You'll be going there to forfeit challenges and study other people's solutions. Below are some platforms you can try out, you can stick with your favorite or use them all. If you know of another platform, go for it! All that matters is that you can study many solutions to the same problem
free trial period
Edabit is an exercise platform that lets you choose from a wide selection of coding challenges to study. The website has some helpful tutorials to get you started and each exercise has some suggested resources to study. You can choose freely between easy and difficult challenges.
Compared with Codewars or Exercism the challenges on Edabit will be a little easier, and the solutions are generally more clear to read and understand. They may not always be the most "clever" solution, but you can pick up some good habits for writing clear and readable code.
LeetCode is full of great challenges, supporting explanations/videos, solutions, and discussions. LeetCode also has many other learning resources to help you take the first steps in Computer Science and algorithms.
Codewars is a website with progressive programming challenges starting at 8 kyu (easiest) all the way upt to 1 kyu (the hardest). You can learn more about Codewars by reading the Codewars Wiki.
Compared with Edabit, the challenges on Codewars can be more challenging. Users on Codewars also submit more complex, "impressive" or imaginative solutions. They may not be best practice, but they can sure be fun to puzzle out.
limited access with free account
CoderByte is somewhere between Codewars and Edabit. There are different levels of challenges and many solutions to study. Some of the challenges come with a video explaining the problem and walking through a solution.
On Exercism you will be able to choose challenges by language feature, submit solutions online, and study other people's solutions (only after you pass).
Some of the exercises are functions, study these. Some of them are classes (Object Oriented Programming), you can skip these.
These exercises are about exploring other people's code, not writing your own. You will be more confident Creating your own code in the future if right now you focus on Reading and Modifying others'.
Don't push too fast to harder and harder challenges. Your goal here is to practice analyzing code, not to solve harder and harder problems. You can learn everything you need to learn by studying easier challenges.
Codewar users write some (overly) clever solutions to simple problems. You can learn a lot about JavaScript and programming from them. The less you struggle to understand the problem the quicker you can lean from their code.
Don't spend time trying to pass the challenges you want to write up. Unlock and forfeit the challenges right away. There is plenty of time in your future to pass challenges on your own, right now your focus should be on understanding others' solutions. This will help you build a mental library of techniques that will serve you better in the long run than being stuck on your own blank page.
After you've finished your analysis give it a go, see if you can't find your own solutions. But first focus on understanding the problem and understanding other's solutions.
After you've chosen the problem you want to write up, create a file called
problem-name.js
in the correct directory and experiment with a few solutions
before choosing the ones you want to write up. Stepping through the solutions
side by side with your Markdown write-up pages will make your time a lot more
productive.
Experimenting with different solutions to the same function will be the best way to understand a challenge's behavior, and the most effective way to come up with good example use cases.
Take a look through the example-quarter-of-the-year/sandbox.test.js example to see what this might look like.
To run the tests from different platforms in your sandbox.test.js
file, you
will need to refactor the test cases from whatever format they are in to use
describe
, it
and expect
. This will take some practice but will become a
routine task. Check out the ./refactoring-tests.mp4
to see it live, here are the examples from the video:
Writing about code can be harder than actually writing it! Spend a little time every day reading through other forks of this repo. How do others write about strategy? What kinds of examples do others come up with? What refactor options do others think of?
When you find someone's work that's especially helpful link to it in this issue and and give them a star! Let them and everyone else know that their work is worth studying. You can also watch their repos to get notifications whenever they commit new changes.
Did you find a fun challenge with many good solutions to study? Link to it in Awesome Challenges.
Do you have a great trick for studying Codewars? Is there a resource you found online that helped you? Share it! Open an issue in this repository and give it a good label so others can find it.
The main goal of these exercises is to write a markdown file analyzing other people's solutions to a programming challenges. You will also be analyzing your own solution to the challenge, when you do this try to see your code as if someone else wrote it.
Along the way you will learn many important "soft skills" including: how to read and write documentation, how to understand source code, how to interpret test cases, and how to explain your code to others.
For each challenge you study create a new folder file in this repository with a README created from this template. Take a look at the example write-up to see what yours might look like. But don't stop there! you can fill each challenge's folder with any notes or resources you found helpful: screen shots of the debugger or JS tutor, diagrams, flowcharts, fun use cases ... whatever helped you understand the challenge and it's solutions.
Would you be more comfortable doing your write-ups in another language than english? The goal of these exercises is to learn JavaScript in programming, if that's easier for you in another language then go for it!
Your write-ups should have these files, at least. Is there something else you want to include? go for it:
/README.md
/other-person.md
: Analyze the solutions written by (at least) 2
different users. Chose solutions that used different strategies. your
write-ups should include:
/remix-x.md
: After studying a few different ways to solve this problem,
how would you want to do it? You don't need to start from an empty function!
In these exercises you should focus on how you would adjust or combine
existing solutions to make something you like more.
other-person.md
, but with an explanation of which solutions
inspired you and how you designed your remix./sandbox.test.js
:
There's an example write-up to study in the
/example-quarter-of-the-year
directory. Hopefully this will help you get the
feel for it. What you can't learn from this example you can learn by studying
other people's write-ups and asking for help.
There is also a template write-up you can use to get started. It has all the required files along with a description of what goes in each section. You can copy-paste the folder for each challenge you study