freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-an.../functional-programming/apply-functional-programmin...

4.5 KiB

id title challengeType videoUrl localeTitle
587d7dab367417b2b2512b6d Apply Functional Programming to Convert Strings to URL Slugs 1 تطبيق برمجة وظيفية لتحويل السلاسل إلى Slug URL

Description

غطت التحديات الأخيرة عدة عدد من صفيفات السلسلة والصفيف المفيدة التي تتبع مبادئ البرمجة الوظيفية. لقد تعلمنا أيضًا عن reduce ، وهي طريقة قوية تستخدم لتقليل المشكلات إلى نماذج أبسط. من متوسطات الحوسبة إلى الفرز ، يمكن تحقيق أي عملية صفيف بتطبيقها. أذكر أن map filter هي حالات خاصة من reduce . دعونا ندمج ما تعلمناه لحل مشكلة عملية. تحتوي العديد من مواقع إدارة المحتوى (CMS) على عناوين وظيفة تتم إضافتها إلى جزء من عنوان URL لأغراض بسيطة للإشارة المرجعية. على سبيل المثال ، إذا كتبت منشورًا متوسطًا بعنوان "Stop Using Reduce" ، فمن المحتمل أن يكون لعنوان URL شكل من أشكال سلسلة العنوان فيه ("... / stop-using-reduction"). ربما تكون قد لاحظت هذا بالفعل على موقع freeCodeCamp.

Instructions

املأ وظيفة urlSlug بحيث يحول title سلسلة ويعيد الإصدار urlSlug لعنوان URL. يمكنك استخدام أي من الطرق المغطاة في هذا القسم ، ولا تستخدم replace . فيما يلي المتطلبات: الإدخال عبارة عن سلسلة تحتوي على مسافات وكلمات ذات عناوين مكتوبة. الإخراج عبارة عن سلسلة تحتوي على مسافات بين الكلمات التي تم استبدالها بواصلة ( - ) يجب أن يكون الإخراج جميع الأحرف ذات الأحجام المنخفضة. يجب ألا يحتوي الإخراج على أية مسافات

Tests

tests:
  - text: يجب ألا يتغير متغير <code>globalTitle</code> .
    testString: 'assert(globalTitle === "Winter Is Coming", "The <code>globalTitle</code> variable should not change.");'
  - text: يجب ألا تستخدم شفرتك طريقة <code>replace</code> لهذا التحدي.
    testString: 'assert(!code.match(/\.replace/g), "Your code should not use the <code>replace</code> method for this challenge.");'
  - text: يجب أن ترجع <code>urlSlug(&quot;Winter Is Coming&quot;)</code> <code>&quot;winter-is-coming&quot;</code> .
    testString: 'assert(urlSlug("Winter Is Coming") === "winter-is-coming", "<code>urlSlug("Winter Is Coming")</code> should return <code>"winter-is-coming"</code>.");'
  - text: يجب أن ترجع <code>urlSlug(&quot; Winter Is  Coming&quot;)</code> <code>&quot;winter-is-coming&quot;</code> .
    testString: 'assert(urlSlug(" Winter Is  Coming") === "winter-is-coming", "<code>urlSlug(" Winter Is  &nbsp;Coming")</code> should return <code>"winter-is-coming"</code>.");'
  - text: <code>urlSlug(&quot;A Mind Needs Books Like A Sword Needs A Whetstone&quot;)</code> <code>&quot;a-mind-needs-books-like-a-sword-needs-a-whetstone&quot;</code> .
    testString: 'assert(urlSlug("A Mind Needs Books Like A Sword Needs A Whetstone") === "a-mind-needs-books-like-a-sword-needs-a-whetstone", "<code>urlSlug("A Mind Needs Books Like A Sword Needs A Whetstone")</code> should return <code>"a-mind-needs-books-like-a-sword-needs-a-whetstone"</code>.");'
  - text: يجب أن ترجع <code>urlSlug(&quot;Hold The Door&quot;)</code> <code>&quot;hold-the-door&quot;</code> .
    testString: 'assert(urlSlug("Hold The Door") === "hold-the-door", "<code>urlSlug("Hold The Door")</code> should return <code>"hold-the-door"</code>.");'

Challenge Seed

// the global variable
var globalTitle = "Winter Is Coming";

// Add your code below this line
function urlSlug(title) {


}
// Add your code above this line

var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"

Solution

// solution required