Public Solving: Checking the sleighs automatically

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

The elves build and try a lot of different sleighs for Santa. Because of the number of sleighs, they are looking for an automated report.
Click here to view the original puzzle.
Each sleigh is already being tested, so they have the data available. It's up to us to check if each system check is passing. If so, we should return a specific letter.
The checks pass if a value is above 90%. The result should be an alphabetically sorted string.
If all checks fail, we should return an X.
I won't describe the solution for this one but rather walk you straight through my implementation.
The sleigh has multiple attributes, but they are not sorted.
So I decided to start with a checkMap object.
This object will keep all the checks in alphabetical order and contain their letter value.
const checkMap = {
accelerometer: 'A',
breaks: 'B',
compass: 'C',
gyroscope: 'G',
humiditySensor: 'H',
langdingSuspension: 'L',
navigation: 'N',
pressureSensor: 'P',
temperatureSensor: 'T',
windSensor: 'W',
};
I want to loop over these checks and add a letter if the value passes the inspection.
Once again, I'll be using the reduce method.
We have to extract the object keys so we can loop over them.
const checks = Object.keys(checkMap).reduce((output, check) => {
// Do check
}, '');
The check is actually the easy part as a value is valid if over 90%.
If that is the case, I add a letter to the output array.
const checks = Object.keys(checkMap).reduce((output, check) => {
if (sleigh[check] >= 0.9) {
output += checkMap[check];
}
return output;
}, '');
What happens here is that if the sleighs check for the current check is above 0.9 (90%), we add the letter for that check to our array.
Now we just need a check if this checks string is empty.
If so, all checks must have failed, and we should return an X.
return checks.length ? checks : 'X';
Let's see how we did by running the test.

That's it! We got there, and we can now safely evaluate all the sleighs.
Do let me know what you would do differently in this solution.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter