সমস্যা
আমাদের দুটি জাভাস্ক্রিপ্ট ফাংশন -
লিখতে হবে- প্রথম ফাংশনটি একটি দীর্ঘ url-এ নেওয়া উচিত এবং এটির সাথে সামঞ্জস্যপূর্ণ একটি ছোট url ফেরত দেওয়া উচিত৷
- দ্বিতীয় ফাংশনটি সংক্ষিপ্ত url-এ নেওয়া উচিত এবং মূল url-এ পুনর্নির্দেশ করা উচিত৷ ৷
উদাহরণ
নিম্নলিখিত কোড -
const url = 'https://www.google.com/search?client=firefox-b-d&q=google+search';
const obj = {};
const urlShortener = (longURL = '') => {
let shortURL = "short.ly/" + longURL.replace(/[^a-z]/g,'').slice(-4);
if(!obj[shortURL]){
obj[shortURL] = longURL;
};
return shortURL;
}
const urlRedirector = (shortURL = '') => {
return obj[shortURL];
};
const short = urlShortener(url);
const original = urlRedirector(short);
console.log(short);
console.log(original); আউটপুট
নিম্নোক্ত কনসোল আউটপুট -
short.ly/arch https://www.google.com/search?client=firefox-b-d&q=google+search