mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-01 01:00:36 -04:00
2.0 KiB
2.0 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| 587d7b88367417b2b2512b44 | Write Arrow Functions with Parameters | 1 | 301223 | write-arrow-functions-with-parameters |
--description--
تماما مثل اي function عادي، يمكنك تمرير الـ arguments إلى arrow function.
const doubler = (item) => item * 2;
doubler(4);
doubler(4) سوف يعيد القيمة 8.
إذا كان للـ arrow function معلمة واحدة، يمكن حذف الأقواس المرفقة بالمعلمة.
const doubler = item => item * 2;
ومن الممكن تمرير أكثر من argument واحدة إلى الـ arrow function.
const multiplier = (item, multi) => item * multi;
multiplier(4, 2);
multiplier(4, 2) سوف يعيد القيمة 8.
--instructions--
قم بإعادة كتابة دالة myConcat التي تضيف محتويات arr2 إلى arr1 بحيث تستخدم الدالة الـ arrow function syntax.
--hints--
يجب عليك استبدال كلمة var.
(getUserInput) => assert(!getUserInput('index').match(/var/g));
myConcat يجب أن يكون متغير ثابت (باستخدام const).
(getUserInput) => assert(getUserInput('index').match(/const\s+myConcat/g));
myConcat يجب أن تكون arrow function مع معلمين (two parameters)
assert(
/myConcat=\(\w+,\w+\)=>/.test(code.replace(/\s/g, '')) &&
typeof myConcat === 'function'
);
myConcat() يجب أن يعيد [1, 2, 3, 4, 5].
assert.deepEqual(myConcat([1, 2], [3, 4, 5]), [1, 2, 3, 4, 5]);
لا ينبغي استخدام كلمة function.
(getUserInput) => assert(!getUserInput('index').match(/function/g));
--seed--
--seed-contents--
var myConcat = function(arr1, arr2) {
return arr1.concat(arr2);
};
console.log(myConcat([1, 2], [3, 4, 5]));
--solutions--
const myConcat = (arr1, arr2) => {
return arr1.concat(arr2);
};
console.log(myConcat([1, 2], [3, 4, 5]));