हमें एक JavaScript फंक्शन लिखना है जो एक स्ट्रिंग और एक संख्या n लेता है और पहले n कैरेक्टर हटाकर दूसरी स्ट्रिंग लौटाता है।
उदाहरण के लिए -
यदि मूल स्ट्रिंग है -
const str = "this is a string" और n = 5,
तो आउटपुट होना चाहिए -
const output = "is a string"
उदाहरण
निम्नलिखित कोड है -
const mobileNumber = '+915389534759385';
const secondNumber = '+198345985734';
const removeN = (str, num) => {
const { length } = str;
if(num > length){
return str;
};
const newStr = str.substr(num, length - num);
return newStr;
};
console.log(removeN(mobileNumber, 3));
console.log(removeN(secondNumber, 2));
आउटपुट
कंसोल में निम्नलिखित आउटपुट है -
5389534759385 98345985734