আমাদের একটি জাভাস্ক্রিপ্ট ফাংশন লিখতে হবে যা দুটি স্ট্রিং নেয় এবং প্রথম স্ট্রিং দ্বিতীয় দিয়ে শুরু হয় কিনা তা পরীক্ষা করে
যেমন −
If the two strings are: “Disaster management report” “Disas” Then our function should return true
চলুন এই ফাংশনের জন্য কোড লিখি −
উদাহরণ
const first = 'The game is on';
const second = 'The';
const startsWith = (first, second) => {
const { length } = second;
const { length: l } = first;
const sub = first.substr(0, length);
return sub === second;
};
console.log(startsWith(first, second)); আউটপুট
কনসোলে আউটপুট হবে −
true