DEV Community

Discussion on: Can you solve this interview problem?

Collapse
 
0shuvo0 profile image
Shuvo

Seems like your code only works is it elements of array is in a particular order

I shuffled the array again and its not working

let url = `[ "6Ly9kZXYudG", "9jb21tZW5", "8vMHNodXZvMC", "aHR0cHM", "0LzFqZTFt" ]`;

const base64 = JSON.parse(url);
const sort = base64.sort(() => 0 - Math.random()).join("");
const decode = atob(sort);

document.getElementById("url").innerHTML =  decode;
Enter fullscreen mode Exit fullscreen mode
Collapse
 
d3skdev profile image
d3skdev

i see, please check my update

Thread Thread
 
0shuvo0 profile image
Shuvo

It works
Pro tip: you can optimize it by first getting the permutation of the array