concat
كطريقة لدمج المصفوفات في صف جديد دون تحوير المصفوفات الأصلية. قارن concat
إلى طريقة push
. يضيف Push
عنصرًا إلى نهاية الصفيف نفسه الذي يطلق عليه ، والذي يحول ذلك الصفيف. إليك مثال على ذلك: var arr = [1، 2، 3]؛يوفر
arr.push ([4، 5، 6])؛
// arr يتم تغييرها إلى [1 ، 2 ، 3 ، [4 ، 5 ، 6]]
// ليس طريقة البرمجة الوظيفية
Concat
طريقة لإضافة عناصر جديدة إلى نهاية صفيف بدون أي تأثيرات جانبية متحولة. nonMutatingPush
بحيث يستخدم concat
لإضافة newItem
إلى نهاية original
بدلاً من push
. يجب على الدالة إرجاع صفيف. concat
.
testString: 'assert(code.match(/\.concat/g), "Your code should use the concat
method.");'
- text: يجب ألا تستخدم شفرتك طريقة push
.
testString: 'assert(!code.match(/\.push/g), "Your code should not use the push
method.");'
- text: يجب أن لا تتغير الصفيف first
.
testString: 'assert(JSON.stringify(first) === JSON.stringify([1, 2, 3]), "The first
array should not change.");'
- text: لا يجب تغيير الصفيف second
.
testString: 'assert(JSON.stringify(second) === JSON.stringify([4, 5]), "The second
array should not change.");'
- text: 'nonMutatingPush([1, 2, 3], [4, 5])
[1, 2, 3, 4, 5]
.'
testString: 'assert(JSON.stringify(nonMutatingPush([1, 2, 3], [4, 5])) === JSON.stringify([1, 2, 3, 4, 5]), "nonMutatingPush([1, 2, 3], [4, 5])
should return [1, 2, 3, 4, 5]
.");'
```