আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা দুটি স্ট্রিং নেবে, বলুন string1 এবং string2, এবং নির্ধারণ করবে string1 কি string2 দিয়ে শেষ হচ্ছে।
উদাহরণস্বরূপ:
"The game is on" এখানে, "on" true ফেরত দেবে
যখন,
"the game is off" উপরে, "of" false ফেরত দেবে
এই ফাংশনের কোড লিখি:
উদাহরণ
const first = 'The game is on';
const second = ' on';
const endsWith = (first, second) => {
const { length } = second;
const { length: l } = first;
const sub = first.substr(l - length, length);
return sub === second;
};
console.log(endsWith(first, second));
console.log(endsWith(first, ' off'));
আউটপুট
কনসোলে আউটপুট হবে:
true false