--- id: 587d78b2367417b2b2512b0f title: Remove Items from an Array with pop() and shift() challengeType: 1 videoUrl: '' localeTitle: إزالة العناصر من صفيف مع pop () و shift () --- ## Description
كل من push() و unshift() لهما unshift() : pop() و shift() . كما قد تكون قد خمنت الآن ، بدلاً من إضافة ، يزيل pop() عنصرًا من نهاية صفيف ، بينما يزيل shift() عنصرًا من البداية. الاختلاف الرئيسي بين pop() و shift() وأبناء عمومتهم push() و unshift() ، هو أن كلا الأسلوبين لا unshift() معلمات ، وكل منهما يسمح فقط بتعديل مصفوفة بواسطة عنصر واحد في كل مرة. لنلقي نظرة:
اسمحوا تحيات = [ماذا يكون ما يصل؟ ، 'مرحبا' ، 'انظر يا!'] ؛

greetings.pop ()؛
// الآن تساوي ['ما الأمر؟' ، 'مرحبا']

greetings.shift ()؛
// الآن تساوي ['مرحبا']
يمكننا أيضًا إرجاع قيمة العنصر الذي تمت إزالته باستخدام أي من الطريقتين التاليتين:
دعونا برزت = تحيات. pop () ؛
// إرجاع "مرحبًا"
// تحيات الآن تساوي []
## Instructions
لقد حددنا وظيفة ، popShift ، والتي تأخذ مصفوفة كوسيطة وترجع مصفوفة جديدة. قم بتعديل الوظيفة ، باستخدام pop() و shift() ، لإزالة العناصر الأولى والأخيرة لصفيف الوسيطة ، وتعيين العناصر التي تم إزالتها للمتغيرات الخاصة بها ، بحيث يحتوي الصفيف الذي تم إرجاعه على قيمها.
## Tests
```yml tests: - text: 'popShift(["challenge", "is", "not", "complete"]) يجب أن يعيد ["challenge", "complete"]' testString: 'assert.deepEqual(popShift(["challenge", "is", "not", "complete"]), ["challenge", "complete"], "popShift(["challenge", "is", "not", "complete"]) should return ["challenge", "complete"]");' - text: يجب أن تستخدم وظيفة popShift الأسلوب pop() testString: 'assert.notStrictEqual(popShift.toString().search(/\.pop\(/), -1, "The popShift function should utilize the pop() method");' - text: يجب أن تستخدم وظيفة popShift طريقة shift() testString: 'assert.notStrictEqual(popShift.toString().search(/\.shift\(/), -1, "The popShift function should utilize the shift() method");' ```
## Challenge Seed
```js function popShift(arr) { let popped; // change this line let shifted; // change this line return [shifted, popped]; } // do not change code below this line console.log(popShift(['challenge', 'is', 'not', 'complete'])); ```
## Solution
```js // solution required ```