हमें एक जावास्क्रिप्ट फंक्शन लिखना है जो एक स्ट्रिंग और एक नंबर k ले और स्ट्रिंग से पहले k कैरेक्टर्स हटाकर दूसरी स्ट्रिंग वापस करे।
उदाहरण के लिए: यदि मूल स्ट्रिंग है:
const str = "this is a string"
और,
n = 4
तो आउटपुट होना चाहिए:
const output = " is a string"
उदाहरण
इसके लिए कोड:
const str = 'this is a string'; const removeN = (str, num) => { const { length } = str; if(num > length){ return str; }; const newStr = str.substr(num, length - num); return newStr; }; console.log(removeN(str, 3));आउटपुट
कंसोल में आउटपुट:
s is a string