Here's your first task: can you think of how to improve the code so that in the re-randomization, it elegantly checks to see whether the new randomization also exists in our database? Hint: you may want to create a separate helper function or two.
Maybe you arrived at something like this (https://github.com/PacktPublishing/Hands-on-JavaScript-for-Python-Developers/tree/master/chapter-13/starship-app-solution1):
const eliminateExistingShips = async () => {
const shipNames = require('../data/starship-names');
const ships = await storage.values();
const names = Object.values(ships).map((value, index, arr) => {
return value.name;
});
const availableNames = shipNames.names.filter((val) => {
return !names.includes(val);
});
const unavailableRegistryNumbers = Object.values(ships).map((value, index,
arr) => {
return value.registry;
});
return { names: availableNames, unavailableRegistries:
unavailableRegistryNumbers };
}
And to use it, execute...