freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-an.../basic-data-structures/combine-arrays-with-the-spr...

2.8 KiB

id title challengeType videoUrl localeTitle
587d7b7b367417b2b2512b17 Combine Arrays with the Spread Operator 1 الجمع بين المصفوفات مع المشغل انتشار

Description

ميزة أخرى ضخمة لمشغل الانتشار ، هي القدرة على الجمع بين المصفوفات ، أو لإدراج جميع عناصر صفيف في آخر ، في أي مؤشر. باستخدام صيغ تركيبية أكثر تقليدية ، يمكننا تجميع صفائف ، لكن هذا يسمح لنا فقط بدمج المصفوفات في نهاية واحد ، وفي بداية أخرى. بناء الجملة Spread يجعل العملية التالية بسيطة للغاية:
دع هذا aarray = ['sage'، 'rosemary'، 'parsley'، 'thyme']؛

اترك ذلكالرائحة = ['basil' ، 'cilantro' ، ... thisArray ، 'الكزبرة'] ؛
/ / أن الآن يساوي [basil] ، 'cilantro' ، 'sage' ، 'rosemary' ، 'parsley' ، 'thyme' ، 'coriander']
باستخدام صيغة الانتشار ، حققنا للتو عملية من شأنها أن تكون أكثر تعقيدا وأكثر استعراضا لو استخدمنا الطرق التقليدية.

Instructions

لقد قمنا بتعريف دالة spreadOut التي تقوم بارجاع sentence المتغيرة ، قم بتعديل الوظيفة باستخدام معامل الانتشار بحيث يقوم بإرجاع الصفيف ['learning', 'to', 'code', 'is', 'fun'] .

Tests

tests:
  - text: '<code>spreadOut</code> يجب أن تعود <code>[&quot;learning&quot;, &quot;to&quot;, &quot;code&quot;, &quot;is&quot;, &quot;fun&quot;]</code>'
    testString: 'assert.deepEqual(spreadOut(), ["learning", "to", "code", "is", "fun"], "<code>spreadOut</code> should return <code>["learning", "to", "code", "is", "fun"]</code>");'
  - text: يجب أن تستخدم دالة <code>spreadOut</code> بنية الانتشار
    testString: 'assert.notStrictEqual(spreadOut.toString().search(/[...]/), -1, "The <code>spreadOut</code> function should utilize spread syntax");'

Challenge Seed

function spreadOut() {
  let fragment = ['to', 'code'];
  let sentence; // change this line
  return sentence;
}

// do not change code below this line
console.log(spreadOut());

Solution

// solution required