--- id: 587d7da9367417b2b2512b67 title: Add Elements to the End of an Array Using concat Instead of push challengeType: 1 videoUrl: '' localeTitle: إضافة عناصر إلى نهاية صفيف باستخدام concat بدلاً من الضغط --- ## Description
البرمجة الوظيفية هي كل شيء عن إنشاء واستخدام وظائف غير متحولة. قدم التحدي الأخير طريقة concat كطريقة لدمج المصفوفات في صف جديد دون تحوير المصفوفات الأصلية. قارن concat إلى طريقة push . يضيف Push عنصرًا إلى نهاية الصفيف نفسه الذي يطلق عليه ، والذي يحول ذلك الصفيف. إليك مثال على ذلك:
var arr = [1، 2، 3]؛
arr.push ([4، 5، 6])؛
// arr يتم تغييرها إلى [1 ، 2 ، 3 ، [4 ، 5 ، 6]]
// ليس طريقة البرمجة الوظيفية
يوفر Concat طريقة لإضافة عناصر جديدة إلى نهاية صفيف بدون أي تأثيرات جانبية متحولة.
## Instructions
تغيير الدالة nonMutatingPush بحيث يستخدم concat لإضافة newItem إلى نهاية original بدلاً من push . يجب على الدالة إرجاع صفيف.
## Tests
```yml tests: - text: يجب أن تستخدم التعليمات البرمجية الخاصة بك طريقة 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].");' ```
## Challenge Seed
```js function nonMutatingPush(original, newItem) { // Add your code below this line return original.push(newItem); // Add your code above this line } var first = [1, 2, 3]; var second = [4, 5]; nonMutatingPush(first, second); ```
## Solution
```js // solution required ```