Tell us what’s happening:
Describe your issue in detail here.
//i have solved this problem this way please review once and comment
**Your code so far**
function multiplyAll(arr) {
// let product = 1;
// Only change code below this line
// for (let i = 0; i < arr.length; i++) {
// for (let j = 0; j < arr[i].length; j++) {
// product*=arr[i][j]
// console.log(arr[i][j]);
// }
// }
let flatData=arr.flatMap((currentValue) =>currentValue)
let product=flatData.reduce((acc,mov)=>acc*mov,1)
return product
}
multiplyAll([[1, 2], [3, 4], [5, 6, 7]]);
**Your browser information:**
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36
Challenge: Nesting For Loops
Link to the challenge:
Cool, but can you follow the instructions and solve it with two for loops?
1 Like
Hi @md.farhan0203 !
I have added spoiler tags around your code this is a working solution.
@colinthornton yes i did that after getting answer i comment the loop bro …
yes its working fine code review purpose i posted that
You can format your code by right clicking the editor and selecting “Format Document”, or use the listed keyboard shortcut. This makes all the spacing consistent, which in turn makes it easier to read. If you’re going to ask for people to review your code, you should make it easy to read.
I agree with everything Jeremy said, except for #3 because that’s the default in Prettier, and I just let Prettier do its thing (the supposed advantage is so that you don’t have to add the parentheses in the case that you need to add a second argument, but I’ve grown to like the consistency as well).
1 Like
colinthornton:
I agree with everything Jeremy said, except for #3 because that’s the default in Prettier, and I just let Prettier do it’s thing (the supposed advantage is so that you don’t have to add the parentheses in the case that you need to add a second argument, but I’ve grown to like the consistency as well).
That’s fair. So long as you have a reason
1 Like
1)its combo of flat and map we can use flatMap to make flat and make iterate it
2)ok function multiplyAll(arr) {
let flatData=arr.flatMap((currentValue) =>currentValue).reduce((acc,mov)=>acc*mov,1)
return flatData
3)for findind product start with 1 else all goes 0
4)to iterate it
5)current value
@JeremyLT thank you so much …i got it…all my mistakes…
1 Like
system
Closed
September 14, 2022, 11:13pm
13
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.