हमें एक जावास्क्रिप्ट फंक्शन लिखना है जो नंबर्स का ऐरे ले। फिर फंक्शन को ऐरे में सबसे छोटे नंबर का इंडेक्स वापस करना चाहिए।
उदाहरण
इसके लिए कोड:
const arr = [3, 56, 56, 23, 7, 76, -2, 345, 45, 76, 3]; const lowestIndex = arr => { const creds = arr.reduce((acc, val, ind) => { let { num, index } = acc; if(val < num){ num = val; index = ind; }; return { num, index }; }, { num: Infinity, index: -1 }); return creds.index; }; console.log(lowestIndex(arr));आउटपुट
कंसोल में आउटपुट:
6