fix: converted single to triple backticks4 (#36231)
This commit is contained in:
@@ -23,14 +23,15 @@ localeTitle: تطبيق برمجة وظيفية لتحويل السلاسل إل
|
||||
|
||||
### حل بديل
|
||||
|
||||
`// the global variable
|
||||
var globalTitle = "Winter Is Coming";
|
||||
|
||||
// Add your code below this line
|
||||
function urlSlug(title) {
|
||||
return title.toLowerCase().trim().split(/\s+/).join('-');
|
||||
}
|
||||
// Add your code above this line
|
||||
|
||||
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
|
||||
`
|
||||
```javascript
|
||||
// the global variable
|
||||
var globalTitle = "Winter Is Coming";
|
||||
|
||||
// Add your code below this line
|
||||
function urlSlug(title) {
|
||||
return title.toLowerCase().trim().split(/\s+/).join('-');
|
||||
}
|
||||
// Add your code above this line
|
||||
|
||||
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
|
||||
```
|
||||
@@ -24,10 +24,11 @@ localeTitle: دمج صفيف في سلسلة باستخدام طريقة الا
|
||||
|
||||
### حل:
|
||||
|
||||
`function sentensify(str) {
|
||||
// Add your code below this line
|
||||
return str.split(/\W/).join(' ');
|
||||
// Add your code above this line
|
||||
}
|
||||
sentensify("May-the-force-be-with-you");
|
||||
`
|
||||
```javascript
|
||||
function sentensify(str) {
|
||||
// Add your code below this line
|
||||
return str.split(/\W/).join(' ');
|
||||
// Add your code above this line
|
||||
}
|
||||
sentensify("May-the-force-be-with-you");
|
||||
```
|
||||
@@ -10,22 +10,23 @@ localeTitle: تنفيذ الخريطة على نموذج أولي
|
||||
|
||||
ومن هناك ، يمكننا استخدام forEach أو for loop لإضافة عناصر إلى مصفوفة فارغة تم تعريفها بالفعل ، حيث نقوم بتعديل كل عنصر باستخدام طريقة رد الاتصال المحددة.
|
||||
|
||||
`// the global Array
|
||||
var s = [23, 65, 98, 5];
|
||||
|
||||
Array.prototype.myMap = function(callback){
|
||||
var newArray = [];
|
||||
// Add your code below this line
|
||||
this.forEach(a => newArray.push(callback(a)));
|
||||
// Add your code above this line
|
||||
return newArray;
|
||||
|
||||
};
|
||||
|
||||
var new_s = s.myMap(function(item){
|
||||
return item * 2;
|
||||
});
|
||||
`
|
||||
```javascript
|
||||
// the global Array
|
||||
var s = [23, 65, 98, 5];
|
||||
|
||||
Array.prototype.myMap = function(callback){
|
||||
var newArray = [];
|
||||
// Add your code below this line
|
||||
this.forEach(a => newArray.push(callback(a)));
|
||||
// Add your code above this line
|
||||
return newArray;
|
||||
|
||||
};
|
||||
|
||||
var new_s = s.myMap(function(item){
|
||||
return item * 2;
|
||||
});
|
||||
```
|
||||
|
||||
### روابط مفيدة
|
||||
|
||||
|
||||
@@ -4,22 +4,23 @@ localeTitle: تنفيذ مرشح طريقة على النموذج
|
||||
---
|
||||
## تنفيذ مرشح طريقة على النموذج
|
||||
|
||||
`// the global Array
|
||||
var s = [23, 65, 98, 5];
|
||||
|
||||
Array.prototype.myFilter = function(callback){
|
||||
var newArray = [];
|
||||
// Add your code below this line
|
||||
this.forEach(function(x) {
|
||||
if (callback(x) == true) {
|
||||
newArray.push(x);
|
||||
}
|
||||
})
|
||||
// Add your code above this line
|
||||
return newArray;
|
||||
|
||||
};
|
||||
`
|
||||
```javascript
|
||||
// the global Array
|
||||
var s = [23, 65, 98, 5];
|
||||
|
||||
Array.prototype.myFilter = function(callback){
|
||||
var newArray = [];
|
||||
// Add your code below this line
|
||||
this.forEach(function(x) {
|
||||
if (callback(x) == true) {
|
||||
newArray.push(x);
|
||||
}
|
||||
})
|
||||
// Add your code above this line
|
||||
return newArray;
|
||||
|
||||
};
|
||||
```
|
||||
|
||||
## حل آخر باستخدام looop!
|
||||
|
||||
|
||||
@@ -6,14 +6,15 @@ localeTitle: مقدمة في التجلي والتطبيق الجزئي
|
||||
|
||||
### حل
|
||||
|
||||
`function add(x) {
|
||||
// Add your code below this line
|
||||
return function(y) {
|
||||
return function(z) {
|
||||
return x + y + z;
|
||||
}
|
||||
}
|
||||
// Add your code above this line
|
||||
}
|
||||
add(10)(20)(30);
|
||||
`
|
||||
```javascript
|
||||
function add(x) {
|
||||
// Add your code below this line
|
||||
return function(y) {
|
||||
return function(z) {
|
||||
return x + y + z;
|
||||
}
|
||||
}
|
||||
// Add your code above this line
|
||||
}
|
||||
add(10)(20)(30);
|
||||
```
|
||||
@@ -13,31 +13,33 @@ localeTitle: المتغيرات العالمية ريفاكتور من الوظ
|
||||
|
||||
## الحل 1
|
||||
|
||||
`function add (arr, bookName) {
|
||||
let newArr = [...arr]; // Copy the bookList array to a new array.
|
||||
newArr.push(bookName); // Add bookName parameter to the end of the new array.
|
||||
return newArr; // Return the new array.
|
||||
}
|
||||
|
||||
function remove (arr, bookName) {
|
||||
let newArr = [...arr]; // Copy the bookList array to a new array.
|
||||
if (newArr.indexOf(bookName) >= 0) { // Check whether the bookName parameter is in new array.
|
||||
/.
|
||||
newArr.splice(newArr.indexOf(bookName), 1); // Remove the given paramater from the new array.
|
||||
return newArr; // Return the new array.
|
||||
}
|
||||
}
|
||||
`
|
||||
```javascript
|
||||
function add (arr, bookName) {
|
||||
let newArr = [...arr]; // Copy the bookList array to a new array.
|
||||
newArr.push(bookName); // Add bookName parameter to the end of the new array.
|
||||
return newArr; // Return the new array.
|
||||
}
|
||||
|
||||
function remove (arr, bookName) {
|
||||
let newArr = [...arr]; // Copy the bookList array to a new array.
|
||||
if (newArr.indexOf(bookName) >= 0) { // Check whether the bookName parameter is in new array.
|
||||
/.
|
||||
newArr.splice(newArr.indexOf(bookName), 1); // Remove the given paramater from the new array.
|
||||
return newArr; // Return the new array.
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## الحل 2
|
||||
|
||||
`function add (list,bookName) {
|
||||
return [...list, bookName];
|
||||
}
|
||||
|
||||
function remove (list,bookName) {
|
||||
if (list.indexOf(bookName) >= 0) {
|
||||
return list.filter((item) => item !== bookName);
|
||||
}
|
||||
}
|
||||
`
|
||||
```javascript
|
||||
function add (list,bookName) {
|
||||
return [...list, bookName];
|
||||
}
|
||||
|
||||
function remove (list,bookName) {
|
||||
if (list.indexOf(bookName) >= 0) {
|
||||
return list.filter((item) => item !== bookName);
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -10,13 +10,14 @@ localeTitle: إرجاع صفيف Sorted دون تغيير في صفيف الأص
|
||||
|
||||
### حل
|
||||
|
||||
`var globalArray = [5, 6, 3, 2, 9];
|
||||
function nonMutatingSort(arr) {
|
||||
// Add your code below this line
|
||||
return [].concat(arr).sort(function(a, b) {
|
||||
return a - b;
|
||||
});
|
||||
// Add your code above this line
|
||||
}
|
||||
nonMutatingSort(globalArray);
|
||||
`
|
||||
```javascript
|
||||
var globalArray = [5, 6, 3, 2, 9];
|
||||
function nonMutatingSort(arr) {
|
||||
// Add your code below this line
|
||||
return [].concat(arr).sort(function(a, b) {
|
||||
return a - b;
|
||||
});
|
||||
// Add your code above this line
|
||||
}
|
||||
nonMutatingSort(globalArray);
|
||||
```
|
||||
@@ -12,20 +12,22 @@ localeTitle: عودة جزء من صفيف باستخدام طريقة شريح
|
||||
|
||||
يمكن كتابة الدالة ببساطة عن طريق كتابة سطر واحد من التعليمات البرمجية - عبارة return. تمامًا كما في المثال المعطى ، قم `beginSlice` المصفوفة التي تأخذها الدالة كمعلمة باستخدام معلمات `beginSlice` و `endSlice` كمعلمات `endSlice` `slice()` . تذكر بنية طريقة `slice()` :
|
||||
|
||||
`var arr = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
|
||||
arr.slice([index-to-begin-slice] , [index-to-end-slice]);
|
||||
`
|
||||
```javascript
|
||||
var arr = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
|
||||
arr.slice([index-to-begin-slice] , [index-to-end-slice]);
|
||||
```
|
||||
|
||||
### حل
|
||||
|
||||
`function sliceArray(anim, beginSlice, endSlice) {
|
||||
// Add your code below this line
|
||||
return anim.slice(beginSlice, endSlice);
|
||||
// Add your code above this line
|
||||
}
|
||||
var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
|
||||
sliceArray(inputAnim, 1, 3);
|
||||
`
|
||||
```javascript
|
||||
function sliceArray(anim, beginSlice, endSlice) {
|
||||
// Add your code below this line
|
||||
return anim.slice(beginSlice, endSlice);
|
||||
// Add your code above this line
|
||||
}
|
||||
var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
|
||||
sliceArray(inputAnim, 1, 3);
|
||||
```
|
||||
|
||||
#### روابط ذات صلة:
|
||||
|
||||
|
||||
@@ -8,25 +8,27 @@ localeTitle: فرز صفيف أبجديا باستخدام طريقة الفرز
|
||||
|
||||
في المثال المعطى ، نرى كيف نكتب دالة ستعيد مصفوفة جديدة بترتيب أبجدي معكوس.
|
||||
|
||||
`function reverseAlpha(arr) {
|
||||
return arr.sort(function(a, b) {
|
||||
return a < b;
|
||||
});
|
||||
}
|
||||
reverseAlpha(['l', 'h', 'z', 'b', 's']);
|
||||
// Returns ['z', 's', 'l', 'h', 'b']
|
||||
`
|
||||
```javascript
|
||||
function reverseAlpha(arr) {
|
||||
return arr.sort(function(a, b) {
|
||||
return a < b;
|
||||
});
|
||||
}
|
||||
reverseAlpha(['l', 'h', 'z', 'b', 's']);
|
||||
// Returns ['z', 's', 'l', 'h', 'b']
|
||||
```
|
||||
|
||||
باستخدام هذا المنطق ، ببساطة عكس هندسة وظيفة لإرجاع مجموعة جديدة بالترتيب الأبجدي.
|
||||
|
||||
### حل
|
||||
|
||||
`function alphabeticalOrder(arr) {
|
||||
// Add your code below this line
|
||||
return arr.sort(function(a,b) {
|
||||
return a > b;
|
||||
});
|
||||
// Add your code above this line
|
||||
}
|
||||
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
|
||||
`
|
||||
```javascript
|
||||
function alphabeticalOrder(arr) {
|
||||
// Add your code below this line
|
||||
return arr.sort(function(a,b) {
|
||||
return a > b;
|
||||
});
|
||||
// Add your code above this line
|
||||
}
|
||||
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
|
||||
```
|
||||
@@ -12,10 +12,11 @@ localeTitle: تقسيم سلسلة في صفيف باستخدام طريقة ا
|
||||
|
||||
### حل
|
||||
|
||||
`function splitify(str) {
|
||||
// Add your code below this line
|
||||
return str.split(/\W/);
|
||||
// Add your code above this line
|
||||
}
|
||||
splitify("Hello World,I-am code");
|
||||
`
|
||||
```javascript
|
||||
function splitify(str) {
|
||||
// Add your code below this line
|
||||
return str.split(/\W/);
|
||||
// Add your code above this line
|
||||
}
|
||||
splitify("Hello World,I-am code");
|
||||
```
|
||||
@@ -29,12 +29,13 @@ localeTitle: استخدم كل أسلوب للتحقق من أن كل عنصر
|
||||
|
||||
## حل بديل
|
||||
|
||||
`function checkPositive(arr) {
|
||||
// Add your code below this line
|
||||
return arr.every(function(value) {
|
||||
return value > 0;
|
||||
});
|
||||
// Add your code above this line
|
||||
}
|
||||
checkPositive([1, 2, 3, -4, 5]);
|
||||
`
|
||||
```javascript
|
||||
function checkPositive(arr) {
|
||||
// Add your code below this line
|
||||
return arr.every(function(value) {
|
||||
return value > 0;
|
||||
});
|
||||
// Add your code above this line
|
||||
}
|
||||
checkPositive([1, 2, 3, -4, 5]);
|
||||
```
|
||||
@@ -10,11 +10,12 @@ localeTitle: استخدم طريقة التصفية لاستخراج البيا
|
||||
|
||||
### حل
|
||||
|
||||
`// Add your code below this line
|
||||
|
||||
var filteredList = watchList.map(function(e) {
|
||||
return {title: e["Title"], rating: e["imdbRating"]}
|
||||
}).filter((e) => e.rating >= 8);
|
||||
|
||||
console.log(filteredList);
|
||||
`
|
||||
```javascript
|
||||
// Add your code below this line
|
||||
|
||||
var filteredList = watchList.map(function(e) {
|
||||
return {title: e["Title"], rating: e["imdbRating"]}
|
||||
}).filter((e) => e.rating >= 8);
|
||||
|
||||
console.log(filteredList);
|
||||
```
|
||||
@@ -14,8 +14,9 @@ localeTitle: استخدم بعض الأسلوب للتحقق من أن أي عن
|
||||
|
||||
### حل:
|
||||
|
||||
`function checkPositive(arr) {
|
||||
return arr.some((elem) => elem > 0);
|
||||
}
|
||||
checkPositive([1, 2, 3, -4, 5]);
|
||||
`
|
||||
```javascript
|
||||
function checkPositive(arr) {
|
||||
return arr.some((elem) => elem > 0);
|
||||
}
|
||||
checkPositive([1, 2, 3, -4, 5]);
|
||||
```
|
||||
Reference in New Issue
Block a user