Some people just want to see the world burn lol!!!!
Fun exercise nonetheless, here is what I came up with in 5 minutes. I did it in NodeJS though.
A couple of notes on the solution:
isValidUrl
But basically the logic is this:
const permutator = (inputArr) => { let result = []; const permute = (arr, m = []) => { if (arr.length === 0) { result.push(m); } else { for (let i = 0; i < arr.length; i++) { const curr = arr.slice(); const next = curr.splice(i, 1); permute(curr.slice(), m.concat(next)); } } } permute(inputArr); return result; } const isValidUrl = (candidateUrl) => { return /^https:\/\/dev.to\/([\w0-9]+\/?)+$/i.test(candidateUrl); } const array = url.replace(/[\[ \]"]/g, '').split(',') const correctUrl = permutator(array) .map(p => p.join('')) .map(s => Buffer.from(s, 'base64').toString()) .filter(isValidUrl) .pop(); console.log(correctUrl);
Nice 💓
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Some people just want to see the world burn lol!!!!
Fun exercise nonetheless, here is what I came up with in 5 minutes. I did it in NodeJS though.
A couple of notes on the solution:
isValidUrl
function to do so, without changing anything elseBut basically the logic is this:
Nice 💓