mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-31 06:01:50 -05:00
1.9 KiB
1.9 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
| id | title | challengeType | videoUrl | forumTopicId | dashedName |
|---|---|---|---|---|---|
| 56533eb9ac21ba0edf2244e1 | الحلَقات For المتداخلة | 1 | https://scrimba.com/c/cRn6GHM | 18248 | nesting-for-loops |
--description--
إذا كان لديك قائمة متعددة الأبعاد، يمكنك استخدام نفس المنطق مثل النقطة السابقة للمرور علي من كل من القائمة وأي قوائم فرعية. إليك مثال:
const arr = [
[1, 2], [3, 4], [5, 6]
];
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
هذا يخرج كل عنصر فرعي في arr واحد تلو الأخر. لاحظ أنه فيما يتعلق بالحلقة الداخلية، نحن نتحقق من .length الخاص إلى arr[i]، لما كان arr[i] هو نفسه قائمة.
--instructions--
عدل الوظيفة multiplyAll بحيث تظهر ناتج ضرب جميع الأرقام في القائمات الفرعية من arr.
--hints--
يجب أن ينتج multiplyAll([[1], [2], [3]]) قيمة 6
assert(multiplyAll([[1], [2], [3]]) === 6);
يجب أن ينتج multiplyAll([[1, 2], [3, 4], [5, 6, 7]]) قيمة 5040
assert(
multiplyAll([
[1, 2],
[3, 4],
[5, 6, 7]
]) === 5040
);
يجب أن ينتج multiplyAll([[5, 1], [0.2, 4, 0.5], [3, 9]]) قيمة 54
assert(
multiplyAll([
[5, 1],
[0.2, 4, 0.5],
[3, 9]
]) === 54
);
--seed--
--seed-contents--
function multiplyAll(arr) {
let product = 1;
// Only change code below this line
// Only change code above this line
return product;
}
multiplyAll([[1, 2], [3, 4], [5, 6, 7]]);
--solutions--
function multiplyAll(arr) {
let product = 1;
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
product *= arr[i][j];
}
}
return product;
}