Files
freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/basic-javascript/manipulate-arrays-with-pop.md
2022-10-20 09:13:17 -07:00

2.3 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
56bbb991ad1ed5201cd392cc تغيير القوائم (Arrays) باستخدام pop() 1 https://scrimba.com/c/cRbVZAB 18236 manipulate-arrays-with-pop

--description--

طريقة أخرى لتغيير البيانات في قائمة (Array) هي باستخدام الوظيفة .pop().

تستخدم الوظيفة .pop() لإزالة قيمة من نهاية القائمة. يمكننا تخزين هذه القيمة المستخرجة عن طريق تعيينها إلى متغير. بعبارة أخرى، تزيل الوظيفة .pop() العنصر الأخير من قائمة وتنتج ذلك العنصر.

أي نوع من البيانات يمكن أن تستخرج من القائمة - الأرقام، المقاطع، حتى القوائم المتداخلة.

const threeArr = [1, 4, 6];
const oneDown = threeArr.pop();
console.log(oneDown);
console.log(threeArr);

سيعرض أول console.log قيمة 6، وسيعرض الثاني قيمة [1, 4].

--instructions--

استخدم وظيفة .pop() لإزالة العنصر الأخير من myArray وعيّن القيمة المستخرجة إلى متغير جديد removedFromMyArray.

--hints--

يجب أن يحتوي myArray على [["John", 23]] فقط.

assert(
  (function (d) {
    if (d[0][0] == 'John' && d[0][1] === 23 && d[1] == undefined) {
      return true;
    } else {
      return false;
    }
  })(myArray)
);

يجب عليك استخدام pop() على myArray.

assert(/removedFromMyArray\s*=\s*myArray\s*.\s*pop\s*(\s*)/.test(code));

يجب أن يحتوي removedFromMyArray على ["cat", 2] فقط.

assert(
  (function (d) {
    if (d[0] == 'cat' && d[1] === 2 && d[2] == undefined) {
      return true;
    } else {
      return false;
    }
  })(removedFromMyArray)
);

--seed--

--after-user-code--

if (typeof removedFromMyArray !== 'undefined') (function(y, z){return 'myArray = ' + JSON.stringify(y) + ' & removedFromMyArray = ' + JSON.stringify(z);})(myArray, removedFromMyArray);

--seed-contents--

// Setup
const myArray = [["John", 23], ["cat", 2]];

// Only change code below this line

--solutions--

const myArray = [["John", 23], ["cat", 2]];
const removedFromMyArray = myArray.pop();