কম্পিউটার

জাভাস্ক্রিপ্ট - পরিপূরক রং নির্মাতা


আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা এক এবং শুধুমাত্র ইনপুট হিসাবে হেক্স রঙে নেয়৷

আমাদের ফাংশনটি তখন ইনপুট হিসাবে নেওয়া রঙের পরিপূরক রঙ খুঁজে পাবে।

এখানে কিছু ইনপুট এবং আউটপুট জোড়া রয়েছে -

getComplementaryColor('#142814') = '#ebd7eb';
getComplementaryColor('#ffffff') = '#000000';
getComplementaryColor('#3399ff') = '#cc6600';

উদাহরণ

এর জন্য কোড হবে −

const str1 = '#142814';
const str2 = '#ffffff';
const str3 = '#3399ff';
const getComplementaryColor = (color = '') => {
   const colorPart = color.slice(1);
   const ind = parseInt(colorPart, 16);
   let iter = ((1 << 4 * colorPart.length) - 1 - ind).toString(16);
   while (iter.length < colorPart.length) {
      iter = '0' + iter;
   };
   return '#' + iter;
};
console.log(getComplementaryColor(str1));
console.log(getComplementaryColor(str2));
console.log(getComplementaryColor(str3));

আউটপুট

এবং কনসোলে আউটপুট হবে −

#ebd7eb
#000000
#cc6600

  1. জাভাস্ক্রিপ্ট চলুন

  2. জাভাস্ক্রিপ্ট র্যান্ডম

  3. জাভাস্ক্রিপ্ট প্রতিশ্রুতি

  4. জাভাস্ক্রিপ্ট দুর্বল সেট