समस्या
हमें एक JavaScript फ़ंक्शन लिखना है जो एक ऐरे arr लेता है। हमारा फ़ंक्शन ऐरे के सभी एलिमेंट्स का गुणनफल खोजकर लौटाना चाहिए।
उदाहरण
निम्नलिखिक कोड है −
const arr = [3, 1, 4, 1, 2, -2, -1]; const produceElements = (arr = []) => { const res = arr.reduce((acc, val) => { acc = acc * val; return acc; }, 1); return res; }; console.log(produceElements(arr));आउटपुट
कंसोल आउटपुट निम्नलिखिक है −
48