There’s a sound doing the rounds on TikTok of American comedian, Steve Harvey, laying out his formula for success in the realm of mens’ suits. He claims that from 5 colours of suits (matching jacket and trousers) and 3 colours of shirts, you could make 75 combinations because everything goes with everything else (subjective and outside the scope of this post).
Thought I’d see if he pulled this number out of thin air or not and test my JavaScript at the same time.
Here’s the base I made, using the web search function on attachments to pull in some pics and a scripting block to iterate through all the options and create the matching outfits.
Here’s my little script for those interested / want to grimace at my code;
let articlesTable = base.getTable('Articles')
let outfitsTable = base.getTable('Outfits')
let allArticles = await articlesTable.selectRecordsAsync()
let jackets = allArticles.records.filter((article) => article.getCellValueAsString('Item') === 'Jacket')
let trousers = allArticles.records.filter((article) => article.getCellValueAsString('Item') === 'Trousers')
let shirts = allArticles.records.filter((article) => article.getCellValueAsString('Item') === 'Shirt')
function createOutfits(jackets, trousers, shirts) {
let outfits = []
for (let jacket of jackets) {
for (let trouser of trousers) {
for (let shirt of shirts) {
let outfit = {
jacket: jacket.id,
trouser: trouser.id,
shirt: shirt.id
}
outfits.push(outfit)
}
}
}
return outfits;
}
let outfits = createOutfits(jackets, trousers, shirts)
// output.inspect(outfits)
let outfitsToWrite = outfits.map(outfit => {
return (
{
"Jacket": [{ id: outfit.jacket }],
"Trousers": [{ id: outfit.trouser }],
"Shirt": [{ id: outfit.shirt }]
}
)
})
for (let outfit of outfitsToWrite) {
await outfitsTable.createRecordAsync(outfit)
}```
I really enjoyed this little challenge and thought, this might be the only place I can share it without getting laughed at or confused looks.