fix: converted single to triple backticks4 (#36231)
This commit is contained in:
@@ -20,10 +20,11 @@ localeTitle: استخدم Arrow Functions لكتابة الدالات المجه
|
||||
|
||||
## حل
|
||||
|
||||
`const magic = () => {
|
||||
"use strict";
|
||||
return new Date();
|
||||
};
|
||||
`
|
||||
```javascript
|
||||
const magic = () => {
|
||||
"use strict";
|
||||
return new Date();
|
||||
};
|
||||
```
|
||||
|
||||
طالما أنك تخلصت من الكلمة الرئيسية `var` ، فأنت جيد.
|
@@ -18,18 +18,19 @@ localeTitle: استخدم بناء جملة class لتعريف دالة منشئ
|
||||
|
||||
## حل:
|
||||
|
||||
`function makeClass() {
|
||||
"use strict";
|
||||
/* Alter code below this line */
|
||||
class Vegetable {
|
||||
constructor(name){
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
/* Alter code above this line */
|
||||
return Vegetable;
|
||||
}
|
||||
`
|
||||
```javascript
|
||||
function makeClass() {
|
||||
"use strict";
|
||||
/* Alter code below this line */
|
||||
class Vegetable {
|
||||
constructor(name){
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
/* Alter code above this line */
|
||||
return Vegetable;
|
||||
}
|
||||
```
|
||||
|
||||
\=======
|
||||
|
||||
|
@@ -12,5 +12,6 @@ localeTitle: استخدم Destructuring Assignment لتعيين متغيرات
|
||||
|
||||
هنا هو الحل رمز:
|
||||
|
||||
`const { tomorrow: { max: maxOfTomorrow } } = forecast;
|
||||
`
|
||||
```javascript
|
||||
const { tomorrow: { max: maxOfTomorrow } } = forecast;
|
||||
```
|
@@ -12,10 +12,11 @@ localeTitle: استخدم Destructuring Assignment لتعيين متغيرات
|
||||
|
||||
# إعادة تعيين خصائص باستخدام deconstruction.
|
||||
|
||||
`var basicOjb = {x: 40};
|
||||
//To reassign 'get the value of the x property of basicObj and place its value into bigX' in ES6:
|
||||
const { x: bigX } = basicOjb;
|
||||
consle.log(bigX) // ans = 40
|
||||
`
|
||||
```javascript
|
||||
var basicOjb = {x: 40};
|
||||
//To reassign 'get the value of the x property of basicObj and place its value into bigX' in ES6:
|
||||
const { x: bigX } = basicOjb;
|
||||
consle.log(bigX) // ans = 40
|
||||
```
|
||||
|
||||
ضع قيمة الخاصية الطول 'str' في len.
|
@@ -14,18 +14,19 @@ localeTitle: استخدم Destructuring Assignment لتمرير كائن كمع
|
||||
|
||||
## الحل 1:
|
||||
|
||||
`const half = (function() {
|
||||
"use strict"; // do not change this line
|
||||
|
||||
// change code below this line
|
||||
return function half({max, min}) {
|
||||
// use function argument destructuring
|
||||
return (max + min) / 2.0;
|
||||
};
|
||||
// change code above this line
|
||||
|
||||
})();
|
||||
`
|
||||
```javascript
|
||||
const half = (function() {
|
||||
"use strict"; // do not change this line
|
||||
|
||||
// change code below this line
|
||||
return function half({max, min}) {
|
||||
// use function argument destructuring
|
||||
return (max + min) / 2.0;
|
||||
};
|
||||
// change code above this line
|
||||
|
||||
})();
|
||||
```
|
||||
|
||||
لاحظ أننا ندمر `stats` لتمرير اثنين من صفاتها - `max` `min` - إلى الوظيفة. لا تنس تعديل بيان الإرجاع الثاني. تغيير `stats.max` إلى `max` ، وتغيير `stats.min` إلى `min` فقط.
|
||||
|
||||
@@ -33,15 +34,16 @@ localeTitle: استخدم Destructuring Assignment لتمرير كائن كمع
|
||||
|
||||
هنا هو حل آخر يعمل. ليس الكثير من الاختلاف ، بخلاف حقيقة أن الوظيفة لا تملك اسمًا.
|
||||
|
||||
`const half = (function() {
|
||||
"use strict"; // do not change this line
|
||||
|
||||
// change code below this line
|
||||
return (({max, min}) => {
|
||||
// use function argument destructuring
|
||||
return (max + min) / 2.0;
|
||||
});
|
||||
// change code above this line
|
||||
|
||||
})();
|
||||
`
|
||||
```javascript
|
||||
const half = (function() {
|
||||
"use strict"; // do not change this line
|
||||
|
||||
// change code below this line
|
||||
return (({max, min}) => {
|
||||
// use function argument destructuring
|
||||
return (max + min) / 2.0;
|
||||
});
|
||||
// change code above this line
|
||||
|
||||
})();
|
||||
```
|
@@ -20,48 +20,52 @@ localeTitle: استخدم Destructuring Assignment مع عامل التشغيل
|
||||
|
||||
استخدم destructuring لإنشاء متغير `arr` .
|
||||
|
||||
`function removeFirstTwo(list) {
|
||||
"use strict";
|
||||
// change code below this line
|
||||
const [arr] = list; // change this
|
||||
// change code above this line
|
||||
return arr;
|
||||
}
|
||||
`
|
||||
```javascript
|
||||
function removeFirstTwo(list) {
|
||||
"use strict";
|
||||
// change code below this line
|
||||
const [arr] = list; // change this
|
||||
// change code above this line
|
||||
return arr;
|
||||
}
|
||||
```
|
||||
|
||||
## تلميح 2
|
||||
|
||||
انشر معلمة `list` في `arr` .
|
||||
|
||||
`function removeFirstTwo(list) {
|
||||
"use strict";
|
||||
// change code below this line
|
||||
const [...arr] = list; // change this
|
||||
// change code above this line
|
||||
return arr;
|
||||
}
|
||||
`
|
||||
```javascript
|
||||
function removeFirstTwo(list) {
|
||||
"use strict";
|
||||
// change code below this line
|
||||
const [...arr] = list; // change this
|
||||
// change code above this line
|
||||
return arr;
|
||||
}
|
||||
```
|
||||
|
||||
## تلميح 3
|
||||
|
||||
استبعاد أول عنصرين من صفيف `arr` مع `,,` .
|
||||
|
||||
`function removeFirstTwo(list) {
|
||||
"use strict";
|
||||
// change code below this line
|
||||
const [,,...arr] = list; // change this
|
||||
// change code above this line
|
||||
return arr;
|
||||
}
|
||||
`
|
||||
```javascript
|
||||
function removeFirstTwo(list) {
|
||||
"use strict";
|
||||
// change code below this line
|
||||
const [,,...arr] = list; // change this
|
||||
// change code above this line
|
||||
return arr;
|
||||
}
|
||||
```
|
||||
|
||||
## تنبيه المفسد - الحل إلى الأمام!
|
||||
|
||||
`function removeFirstTwo(list) {
|
||||
"use strict";
|
||||
// change code below this line
|
||||
const [a, b, ...arr] = list;
|
||||
// change code above this line
|
||||
return arr;
|
||||
}
|
||||
`
|
||||
```javascript
|
||||
function removeFirstTwo(list) {
|
||||
"use strict";
|
||||
// change code below this line
|
||||
const [a, b, ...arr] = list;
|
||||
// change code above this line
|
||||
return arr;
|
||||
}
|
||||
```
|
@@ -16,7 +16,8 @@ localeTitle: استخدم التصدير لإعادة استخدام كتلة ت
|
||||
|
||||
## حل
|
||||
|
||||
`"use strict";
|
||||
export const foo = "bar";
|
||||
export const bar = "foo";
|
||||
`
|
||||
```javascript
|
||||
"use strict";
|
||||
export const foo = "bar";
|
||||
export const bar = "foo";
|
||||
```
|
@@ -29,17 +29,20 @@ localeTitle: استخدم Spread Operator لتقييم Arrays في - مكان
|
||||
|
||||
### 3 أمثلة سريعة
|
||||
|
||||
`let numbers = [-12, 160, 0, -3, 51];
|
||||
let minNum = Math.min.apply(null, numbers);
|
||||
console.log(minNum);//-12
|
||||
`
|
||||
```javascript
|
||||
let numbers = [-12, 160, 0, -3, 51];
|
||||
let minNum = Math.min.apply(null, numbers);
|
||||
console.log(minNum);//-12
|
||||
```
|
||||
|
||||
`let numbers = [-12, 160, 0, -3, 51];
|
||||
let minNum = Math.min(numbers);
|
||||
console.log(minNum);//NaN
|
||||
`
|
||||
```javascript
|
||||
let numbers = [-12, 160, 0, -3, 51];
|
||||
let minNum = Math.min(numbers);
|
||||
console.log(minNum);//NaN
|
||||
```
|
||||
|
||||
`let numbers = [-12, 160, 0, -3, 51];
|
||||
let minNum = Math.min(...numbers);
|
||||
console.log(minNum);//-12
|
||||
`
|
||||
```javascript
|
||||
let numbers = [-12, 160, 0, -3, 51];
|
||||
let minNum = Math.min(...numbers);
|
||||
console.log(minNum);//-12
|
||||
```
|
@@ -20,10 +20,11 @@ localeTitle: كتابة وظائف السهم مع المعلمات
|
||||
|
||||
## حل:
|
||||
|
||||
`const myConcat = (arr1, arr2) => {
|
||||
"use strict";
|
||||
return arr1.concat(arr2);
|
||||
};
|
||||
// test your code
|
||||
console.log(myConcat([1, 2], [3, 4, 5]));
|
||||
`
|
||||
```javascript
|
||||
const myConcat = (arr1, arr2) => {
|
||||
"use strict";
|
||||
return arr1.concat(arr2);
|
||||
};
|
||||
// test your code
|
||||
console.log(myConcat([1, 2], [3, 4, 5]));
|
||||
```
|
@@ -14,11 +14,12 @@ ES6 يجعل من السهل ، والخيال ، لكتابة وظائف الإ
|
||||
|
||||
## حل
|
||||
|
||||
`const bicycle = {
|
||||
gear: 2,
|
||||
setGear(newGear) {
|
||||
"use strict";
|
||||
this.gear = newGear;
|
||||
}
|
||||
};
|
||||
`
|
||||
```javascript
|
||||
const bicycle = {
|
||||
gear: 2,
|
||||
setGear(newGear) {
|
||||
"use strict";
|
||||
this.gear = newGear;
|
||||
}
|
||||
};
|
||||
```
|
@@ -14,14 +14,15 @@ localeTitle: كتابة تعريفات كائن حرفي باستخدام حقو
|
||||
|
||||
## حل
|
||||
|
||||
`const createPerson = (name, age, gender) => {
|
||||
"use strict";
|
||||
// change code below this line
|
||||
return {
|
||||
name,
|
||||
age,
|
||||
gender
|
||||
};
|
||||
// change code above this line
|
||||
};
|
||||
`
|
||||
```javascript
|
||||
const createPerson = (name, age, gender) => {
|
||||
"use strict";
|
||||
// change code below this line
|
||||
return {
|
||||
name,
|
||||
age,
|
||||
gender
|
||||
};
|
||||
// change code above this line
|
||||
};
|
||||
```
|
@@ -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]);
|
||||
```
|
@@ -41,10 +41,11 @@ localeTitle: اصنع شخصا
|
||||
|
||||
إذا كنت تواجه مشاكل في كتابة أساليب `setter` ، في ما يلي نموذج لأسلوب `set` :
|
||||
|
||||
`this.setFullName = function(input) {
|
||||
// Insert your code here
|
||||
}
|
||||
`
|
||||
```js
|
||||
this.setFullName = function(input) {
|
||||
// Insert your code here
|
||||
}
|
||||
```
|
||||
|
||||
> _حاول أن تحل المشكلة الآن_
|
||||
|
||||
@@ -56,37 +57,38 @@ localeTitle: اصنع شخصا
|
||||
|
||||
##  الحل الأساسي للكود:
|
||||
|
||||
`var Person = function(firstAndLast) {
|
||||
var fullName = firstAndLast;
|
||||
|
||||
this.getFirstName = function() {
|
||||
return fullName.split(" ")[0];
|
||||
};
|
||||
|
||||
this.getLastName = function() {
|
||||
return fullName.split(" ")[1];
|
||||
};
|
||||
|
||||
this.getFullName = function() {
|
||||
return fullName;
|
||||
};
|
||||
|
||||
this.setFirstName = function(name) {
|
||||
fullName = name + " " + fullName.split(" ")[1];
|
||||
};
|
||||
|
||||
this.setLastName = function(name) {
|
||||
fullName = fullName.split(" ")[0] + " " + name;
|
||||
};
|
||||
|
||||
this.setFullName = function(name) {
|
||||
fullName = name;
|
||||
};
|
||||
};
|
||||
|
||||
var bob = new Person('Bob Ross');
|
||||
bob.getFullName();
|
||||
`
|
||||
```js
|
||||
var Person = function(firstAndLast) {
|
||||
var fullName = firstAndLast;
|
||||
|
||||
this.getFirstName = function() {
|
||||
return fullName.split(" ")[0];
|
||||
};
|
||||
|
||||
this.getLastName = function() {
|
||||
return fullName.split(" ")[1];
|
||||
};
|
||||
|
||||
this.getFullName = function() {
|
||||
return fullName;
|
||||
};
|
||||
|
||||
this.setFirstName = function(name) {
|
||||
fullName = name + " " + fullName.split(" ")[1];
|
||||
};
|
||||
|
||||
this.setLastName = function(name) {
|
||||
fullName = fullName.split(" ")[0] + " " + name;
|
||||
};
|
||||
|
||||
this.setFullName = function(name) {
|
||||
fullName = name;
|
||||
};
|
||||
};
|
||||
|
||||
var bob = new Person('Bob Ross');
|
||||
bob.getFullName();
|
||||
```
|
||||
|
||||
|
||||
### شرح الشفرة:
|
||||
|
@@ -199,17 +199,18 @@ localeTitle: بحث واستبدال
|
||||
|
||||
##  حل رمز متقدم البديل 2:
|
||||
|
||||
`function myReplace(str, before, after) {
|
||||
const myArr = str.split(' ');
|
||||
const [wordToReplace] = myArr.filter(item => item === before);
|
||||
return wordToReplace[0].toUpperCase() !== wordToReplace[0]
|
||||
? myArr.map(item => item === before ? after : item).join(' ')
|
||||
: myArr.map(item => item === before? after[0].toUpperCase() + after.slice(1) : item).join(' ');
|
||||
}
|
||||
|
||||
// test:
|
||||
myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
|
||||
`
|
||||
```javascript
|
||||
function myReplace(str, before, after) {
|
||||
const myArr = str.split(' ');
|
||||
const [wordToReplace] = myArr.filter(item => item === before);
|
||||
return wordToReplace[0].toUpperCase() !== wordToReplace[0]
|
||||
? myArr.map(item => item === before ? after : item).join(' ')
|
||||
: myArr.map(item => item === before? after[0].toUpperCase() + after.slice(1) : item).join(' ');
|
||||
}
|
||||
|
||||
// test:
|
||||
myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
|
||||
```
|
||||
|
||||
#### روابط ذات صلة
|
||||
|
||||
|
@@ -100,8 +100,9 @@ localeTitle: تسعى وتدمر
|
||||
|
||||
## الحل المتقدم للكود:
|
||||
|
||||
`const destroyer = (arr, ...args) => arr.filter(i => !args.includes(i));
|
||||
`
|
||||
```javascript
|
||||
const destroyer = (arr, ...args) => arr.filter(i => !args.includes(i));
|
||||
```
|
||||
|
||||
### شرح الشفرة:
|
||||
|
||||
|
@@ -83,21 +83,22 @@ localeTitle: الاتحاد الفرز
|
||||
|
||||
## بديلة حل رمز الأساسية
|
||||
|
||||
`function uniteUnique(arr) {
|
||||
var args = [...arguments];
|
||||
var result = [];
|
||||
for(var i = 0; i < args.length; i++) {
|
||||
for(var j = 0; j < args[i].length; j++) {
|
||||
if(!result.includes(args[i][j])) {
|
||||
result.push(args[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
|
||||
`
|
||||
```javascript
|
||||
function uniteUnique(arr) {
|
||||
var args = [...arguments];
|
||||
var result = [];
|
||||
for(var i = 0; i < args.length; i++) {
|
||||
for(var j = 0; j < args[i].length; j++) {
|
||||
if(!result.includes(args[i][j])) {
|
||||
result.push(args[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
|
||||
```
|
||||
|
||||
##  حل الشفرة المتوسطة:
|
||||
|
||||
|
@@ -8,30 +8,32 @@ localeTitle: إضافة طرق بعد الوراثة
|
||||
|
||||
تمامًا كما في المثال التالي ، يجب إنشاء مثيل جديد لكائن - `Dog` - ويجب تعيين `prototype` .
|
||||
|
||||
`function Bird() { }
|
||||
Bird.prototype = Object.create(Animal.prototype);
|
||||
Bird.prototype.constructor = Bird;
|
||||
`
|
||||
```javascript
|
||||
function Bird() { }
|
||||
Bird.prototype = Object.create(Animal.prototype);
|
||||
Bird.prototype.constructor = Bird;
|
||||
```
|
||||
|
||||
ثم يجب إضافة وظيفة جديدة - `bark()` - إلى نموذج الكلب.
|
||||
|
||||
### حل
|
||||
|
||||
`function Animal() { }
|
||||
Animal.prototype.eat = function() { console.log("nom nom nom"); };
|
||||
|
||||
function Dog() { }
|
||||
|
||||
// Add your code below this line
|
||||
Dog.prototype = Object.create(Animal.prototype);
|
||||
Dog.prototype.constructor = Dog;
|
||||
Dog.prototype.bark = function() {
|
||||
console.log("Woof woof!");
|
||||
};
|
||||
// Add your code above this line
|
||||
|
||||
let beagle = new Dog();
|
||||
|
||||
beagle.eat(); // Should print "nom nom nom"
|
||||
beagle.bark(); // Should print "Woof!"
|
||||
`
|
||||
```javascript
|
||||
function Animal() { }
|
||||
Animal.prototype.eat = function() { console.log("nom nom nom"); };
|
||||
|
||||
function Dog() { }
|
||||
|
||||
// Add your code below this line
|
||||
Dog.prototype = Object.create(Animal.prototype);
|
||||
Dog.prototype.constructor = Dog;
|
||||
Dog.prototype.bark = function() {
|
||||
console.log("Woof woof!");
|
||||
};
|
||||
// Add your code above this line
|
||||
|
||||
let beagle = new Dog();
|
||||
|
||||
beagle.eat(); // Should print "nom nom nom"
|
||||
beagle.bark(); // Should print "Woof!"
|
||||
```
|
@@ -28,20 +28,21 @@ localeTitle: تغيير النموذج إلى كائن جديد
|
||||
|
||||
## الحل 1:
|
||||
|
||||
`function Dog(name) {
|
||||
this.name = name;
|
||||
}
|
||||
Dog.prototype = {
|
||||
// Add your code below this line
|
||||
numLegs: 2,
|
||||
eat: function(){
|
||||
console.log('nom nom nom');
|
||||
},
|
||||
describe: function(){
|
||||
console.log("My name is " + this.name);
|
||||
}
|
||||
}
|
||||
`
|
||||
```javascript
|
||||
function Dog(name) {
|
||||
this.name = name;
|
||||
}
|
||||
Dog.prototype = {
|
||||
// Add your code below this line
|
||||
numLegs: 2,
|
||||
eat: function(){
|
||||
console.log('nom nom nom');
|
||||
},
|
||||
describe: function(){
|
||||
console.log("My name is " + this.name);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## شرح الشفرة:
|
||||
|
||||
@@ -51,21 +52,22 @@ localeTitle: تغيير النموذج إلى كائن جديد
|
||||
|
||||
## الحل 2:
|
||||
|
||||
`function Dog(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
Dog.prototype = {
|
||||
// Add your code below this line
|
||||
numLegs: 2,
|
||||
eat(){
|
||||
console.log('nom nom nom');
|
||||
},
|
||||
describe(){
|
||||
console.log("My name is " + this.name);
|
||||
}
|
||||
};
|
||||
`
|
||||
```javascript
|
||||
function Dog(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
Dog.prototype = {
|
||||
// Add your code below this line
|
||||
numLegs: 2,
|
||||
eat(){
|
||||
console.log('nom nom nom');
|
||||
},
|
||||
describe(){
|
||||
console.log("My name is " + this.name);
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## شرح الشفرة:
|
||||
|
||||
|
@@ -10,8 +10,9 @@ localeTitle: قم بإنشاء كائن JavaScript أساسي
|
||||
|
||||
### حل:
|
||||
|
||||
`let dog = {
|
||||
name: "George",
|
||||
numLegs: 4
|
||||
};
|
||||
`
|
||||
```javascript
|
||||
let dog = {
|
||||
name: "George",
|
||||
numLegs: 4
|
||||
};
|
||||
```
|
@@ -19,13 +19,14 @@ localeTitle: إنشاء طريقة على كائن
|
||||
|
||||
### حل:
|
||||
|
||||
`let dog = {
|
||||
name: "Spot",
|
||||
numLegs: 4,
|
||||
sayLegs: function() {
|
||||
return "This dog has " + dog.numLegs + " legs.";
|
||||
}
|
||||
};
|
||||
|
||||
dog.sayLegs();
|
||||
`
|
||||
```javascript
|
||||
let dog = {
|
||||
name: "Spot",
|
||||
numLegs: 4,
|
||||
sayLegs: function() {
|
||||
return "This dog has " + dog.numLegs + " legs.";
|
||||
}
|
||||
};
|
||||
|
||||
dog.sayLegs();
|
||||
```
|
@@ -10,9 +10,10 @@ localeTitle: تحديد وظيفة منشئ
|
||||
|
||||
### حل:
|
||||
|
||||
`function Dog() {
|
||||
this.name = "Geogre",
|
||||
this.color = "White",
|
||||
this.numLegs = 4;
|
||||
}
|
||||
`
|
||||
```javascript
|
||||
function Dog() {
|
||||
this.name = "Geogre",
|
||||
this.color = "White",
|
||||
this.numLegs = 4;
|
||||
}
|
||||
```
|
@@ -10,10 +10,11 @@ localeTitle: تمديد البنائين لتلقي الحجج
|
||||
|
||||
### حل:
|
||||
|
||||
`function Dog(name, color) {
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
this.numLegs = 4;
|
||||
}
|
||||
let terrier = new Dog("George","White");
|
||||
`
|
||||
```javascript
|
||||
function Dog(name, color) {
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
this.numLegs = 4;
|
||||
}
|
||||
let terrier = new Dog("George","White");
|
||||
```
|
@@ -12,8 +12,9 @@ localeTitle: وراثة السلوكيات من Supertype
|
||||
|
||||
السماح للحيوان = Object.create (Animal.prototype) ؛
|
||||
|
||||
`### Solution
|
||||
`
|
||||
```
|
||||
### Solution
|
||||
```
|
||||
|
||||
جافا سكريبت
|
||||
|
||||
|
@@ -10,24 +10,25 @@ localeTitle: تكرار جميع الممتلكات
|
||||
|
||||
### حل
|
||||
|
||||
`function Dog(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
Dog.prototype.numLegs = 4;
|
||||
|
||||
let beagle = new Dog("Snoopy");
|
||||
|
||||
let ownProps = [];
|
||||
let prototypeProps = [];
|
||||
|
||||
// Add your code below this line
|
||||
for (let property in beagle) {
|
||||
if(Dog.hasOwnProperty(property)) {
|
||||
ownProps.push(property)
|
||||
}
|
||||
else {
|
||||
prototypeProps.push(property)
|
||||
}
|
||||
}
|
||||
`
|
||||
```javascript
|
||||
function Dog(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
Dog.prototype.numLegs = 4;
|
||||
|
||||
let beagle = new Dog("Snoopy");
|
||||
|
||||
let ownProps = [];
|
||||
let prototypeProps = [];
|
||||
|
||||
// Add your code below this line
|
||||
for (let property in beagle) {
|
||||
if(Dog.hasOwnProperty(property)) {
|
||||
ownProps.push(property)
|
||||
}
|
||||
else {
|
||||
prototypeProps.push(property)
|
||||
}
|
||||
}
|
||||
```
|
@@ -10,11 +10,12 @@ localeTitle: جعل رمز أكثر قابلة لإعادة الاستخدام
|
||||
|
||||
### حل:
|
||||
|
||||
`let dog = {
|
||||
name: "Spot",
|
||||
numLegs: 4,
|
||||
sayLegs: function() {return "This dog has " + this.numLegs + " legs.";}
|
||||
};
|
||||
|
||||
dog.sayLegs();
|
||||
`
|
||||
```javascript
|
||||
let dog = {
|
||||
name: "Spot",
|
||||
numLegs: 4,
|
||||
sayLegs: function() {return "This dog has " + this.numLegs + " legs.";}
|
||||
};
|
||||
|
||||
dog.sayLegs();
|
||||
```
|
@@ -6,7 +6,8 @@ localeTitle: تجاوز الأساليب الموروثة
|
||||
|
||||
# حل
|
||||
|
||||
`Penguin.prototype.fly = function() {
|
||||
return "Alas, this is a flightless bird.";
|
||||
};
|
||||
`
|
||||
```javascript
|
||||
Penguin.prototype.fly = function() {
|
||||
return "Alas, this is a flightless bird.";
|
||||
};
|
||||
```
|
@@ -8,16 +8,17 @@ localeTitle: تذكر تعيين الخاصية منشئ عند تغيير "ال
|
||||
|
||||
# حل
|
||||
|
||||
`Dog.prototype = {
|
||||
|
||||
constructor: Dog, // Solution
|
||||
|
||||
numLegs: 2,
|
||||
eat: function() {
|
||||
console.log("nom nom nom");
|
||||
},
|
||||
describe: function() {
|
||||
console.log("My name is " + this.name);
|
||||
}
|
||||
};
|
||||
`
|
||||
```javascript
|
||||
Dog.prototype = {
|
||||
|
||||
constructor: Dog, // Solution
|
||||
|
||||
numLegs: 2,
|
||||
eat: function() {
|
||||
console.log("nom nom nom");
|
||||
},
|
||||
describe: function() {
|
||||
console.log("My name is " + this.name);
|
||||
}
|
||||
};
|
||||
```
|
@@ -8,22 +8,24 @@ localeTitle: إعادة تعيين منشئ Conherrated الخاصية
|
||||
|
||||
تمت برمجة كائنات `duck` `beagle` لترث خصائص `supertypes` . للكتابة فوق هذين السطرين من التعليمات البرمجية يجب أن تتم كتابتها لتعيين المنشئين إلى المنشئين المطلوبين `Bird` و `Dog` . يوضح التعليمة البرمجية التالية كيف يمكن تحقيق ذلك.
|
||||
|
||||
`Bird.prototype.constructor = Bird;
|
||||
`
|
||||
```javascript
|
||||
Bird.prototype.constructor = Bird;
|
||||
```
|
||||
|
||||
### حل
|
||||
|
||||
`function Animal() { }
|
||||
function Bird() { }
|
||||
function Dog() { }
|
||||
|
||||
Bird.prototype = Object.create(Animal.prototype);
|
||||
Dog.prototype = Object.create(Animal.prototype);
|
||||
|
||||
// Add your code below this line
|
||||
Bird.prototype.constructor = Bird;
|
||||
Dog.prototype.constructor = Dog;
|
||||
|
||||
let duck = new Bird();
|
||||
let beagle = new Dog();
|
||||
`
|
||||
```javascript
|
||||
function Animal() { }
|
||||
function Bird() { }
|
||||
function Dog() { }
|
||||
|
||||
Bird.prototype = Object.create(Animal.prototype);
|
||||
Dog.prototype = Object.create(Animal.prototype);
|
||||
|
||||
// Add your code below this line
|
||||
Bird.prototype.constructor = Bird;
|
||||
Dog.prototype.constructor = Dog;
|
||||
|
||||
let duck = new Bird();
|
||||
let beagle = new Dog();
|
||||
```
|
@@ -8,25 +8,27 @@ localeTitle: قم بتعيين Prototype الخاص بالطفل إلى مثيل
|
||||
|
||||
لا يختلف هذا التحدي عن التحدي الأخير ، حيث يجب عليك إنشاء كائن يرث من النوع `supertype` . فقط هذه المرة سوف يرث `Dog` الفرعي نوع `Animal` الفائق. ببساطة إنشاء مثيل جديد من `Dog.prototype` مثل المثال التالي.
|
||||
|
||||
`Bird.prototype = Object.create(Animal.prototype);
|
||||
`
|
||||
```javascript
|
||||
Bird.prototype = Object.create(Animal.prototype);
|
||||
```
|
||||
|
||||
### حل
|
||||
|
||||
`function Animal() { }
|
||||
|
||||
Animal.prototype = {
|
||||
constructor: Animal,
|
||||
eat: function() {
|
||||
console.log("nom nom nom");
|
||||
}
|
||||
};
|
||||
|
||||
function Dog() { }
|
||||
|
||||
// Add your code below this line
|
||||
Dog.prototype = Object.create(Animal.prototype);
|
||||
|
||||
let beagle = new Dog();
|
||||
beagle.eat(); // Should print "nom nom nom"
|
||||
`
|
||||
```javascript
|
||||
function Animal() { }
|
||||
|
||||
Animal.prototype = {
|
||||
constructor: Animal,
|
||||
eat: function() {
|
||||
console.log("nom nom nom");
|
||||
}
|
||||
};
|
||||
|
||||
function Dog() { }
|
||||
|
||||
// Add your code below this line
|
||||
Dog.prototype = Object.create(Animal.prototype);
|
||||
|
||||
let beagle = new Dog();
|
||||
beagle.eat(); // Should print "nom nom nom"
|
||||
```
|
@@ -12,12 +12,13 @@ localeTitle: فهم خصائص خاصة
|
||||
|
||||
### حل:
|
||||
|
||||
`let canary = new Bird("Tweety");
|
||||
let ownProps = [];
|
||||
// Add your code below this line
|
||||
for(let property in canary) {
|
||||
if(canary.hasOwnProperty(property)) {
|
||||
ownProps.push(property);
|
||||
}
|
||||
}
|
||||
`
|
||||
```javascript
|
||||
let canary = new Bird("Tweety");
|
||||
let ownProps = [];
|
||||
// Add your code below this line
|
||||
for(let property in canary) {
|
||||
if(canary.hasOwnProperty(property)) {
|
||||
ownProps.push(property);
|
||||
}
|
||||
}
|
||||
```
|
@@ -10,17 +10,18 @@ localeTitle: فهم خاصية منشئ
|
||||
|
||||
### حل
|
||||
|
||||
`function Dog(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// Add your code below this line
|
||||
function joinDogFraternity(candidate) {
|
||||
if(candidate.constructor === Dog) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
`
|
||||
```javascript
|
||||
function Dog(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// Add your code below this line
|
||||
function joinDogFraternity(candidate) {
|
||||
if(candidate.constructor === Dog) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
```
|
@@ -10,7 +10,8 @@ localeTitle: فهم تعبير الدالة المستحثة فوراً (IIFE)
|
||||
|
||||
### حل
|
||||
|
||||
`(function() {
|
||||
console.log("A cozy nest is ready");
|
||||
})();
|
||||
`
|
||||
```javascript
|
||||
(function() {
|
||||
console.log("A cozy nest is ready");
|
||||
})();
|
||||
```
|
@@ -10,11 +10,12 @@ localeTitle: استخدم منشئ لإنشاء كائنات
|
||||
|
||||
### حل:
|
||||
|
||||
`function Dog() {
|
||||
this.name = "Rupert";
|
||||
this.color = "brown";
|
||||
this.numLegs = 4;
|
||||
}
|
||||
// Add your code below this line
|
||||
let hound = new Dog();
|
||||
`
|
||||
```javascript
|
||||
function Dog() {
|
||||
this.name = "Rupert";
|
||||
this.color = "brown";
|
||||
this.numLegs = 4;
|
||||
}
|
||||
// Add your code below this line
|
||||
let hound = new Dog();
|
||||
```
|
@@ -10,22 +10,23 @@ localeTitle: استخدم Mixin لإضافة سلوك شائع بين الكائ
|
||||
|
||||
### حل
|
||||
|
||||
`let bird = {
|
||||
name: "Donald",
|
||||
numLegs: 2
|
||||
};
|
||||
|
||||
let boat = {
|
||||
name: "Warrior",
|
||||
type: "race-boat"
|
||||
};
|
||||
|
||||
// Add your code below this line
|
||||
let glideMixin = function(obj) {
|
||||
obj.glide = function() {
|
||||
console.log("Gliding!");
|
||||
}
|
||||
};
|
||||
glideMixin(bird);
|
||||
glideMixin(boat);
|
||||
`
|
||||
```javascript
|
||||
let bird = {
|
||||
name: "Donald",
|
||||
numLegs: 2
|
||||
};
|
||||
|
||||
let boat = {
|
||||
name: "Warrior",
|
||||
type: "race-boat"
|
||||
};
|
||||
|
||||
// Add your code below this line
|
||||
let glideMixin = function(obj) {
|
||||
obj.glide = function() {
|
||||
console.log("Gliding!");
|
||||
}
|
||||
};
|
||||
glideMixin(bird);
|
||||
glideMixin(boat);
|
||||
```
|
@@ -8,35 +8,37 @@ localeTitle: استخدم IIFE لإنشاء وحدة نمطية
|
||||
|
||||
يجب أن تكون ملفوفة في كلا `Mixin` 's في `funModule` جديدة لذا نقطة بداية esay للتعليق خارج الكود حتى الآن.
|
||||
|
||||
`/*let isCuteMixin = function(obj) {
|
||||
obj.isCute = function() {
|
||||
return true;
|
||||
};
|
||||
};
|
||||
let singMixin = function(obj) {
|
||||
obj.sing = function() {
|
||||
console.log("Singing to an awesome tune");
|
||||
};
|
||||
};
|
||||
*/
|
||||
`
|
||||
```javascript
|
||||
/*let isCuteMixin = function(obj) {
|
||||
obj.isCute = function() {
|
||||
return true;
|
||||
};
|
||||
};
|
||||
let singMixin = function(obj) {
|
||||
obj.sing = function() {
|
||||
console.log("Singing to an awesome tune");
|
||||
};
|
||||
};
|
||||
*/
|
||||
```
|
||||
|
||||
ثم أدناه ابدأ بكتابة كود `funModule` الجديد. داخل الوحدة النمطية الجديدة ، تحتاج إلى كتابة بيان إرجاع لإرجاع كتل التعليمات البرمجية `Mixin` . ما عليك سوى نسخ كل من الكود الأصلي لكتل `Mixin` إلى كود الوحدة الجديدة ، ولكن تذكر أن تفصل كل من المزيج مع `,`
|
||||
|
||||
### حل
|
||||
|
||||
`let funModule = (function() {
|
||||
return {
|
||||
isCuteMixin: function(obj) {
|
||||
obj.isCute = function() {
|
||||
return true;
|
||||
};
|
||||
},
|
||||
singMixin: function(obj) {
|
||||
obj.sing = function() {
|
||||
console.log("Singing to an awesome tune");
|
||||
};
|
||||
}
|
||||
}
|
||||
})();
|
||||
`
|
||||
```javascript
|
||||
let funModule = (function() {
|
||||
return {
|
||||
isCuteMixin: function(obj) {
|
||||
obj.isCute = function() {
|
||||
return true;
|
||||
};
|
||||
},
|
||||
singMixin: function(obj) {
|
||||
obj.sing = function() {
|
||||
console.log("Singing to an awesome tune");
|
||||
};
|
||||
}
|
||||
}
|
||||
})();
|
||||
```
|
@@ -8,23 +8,25 @@ localeTitle: استخدم Dot Notation للوصول إلى خصائص كائن
|
||||
|
||||
ستقوم التعليمة البرمجية التالية ببساطة طباعة `property1` من كائن `obj` .
|
||||
|
||||
`let obj = {
|
||||
property1 = 1,
|
||||
property2 = 2
|
||||
};
|
||||
|
||||
console.log(obj.property1);
|
||||
`
|
||||
```javascript
|
||||
let obj = {
|
||||
property1 = 1,
|
||||
property2 = 2
|
||||
};
|
||||
|
||||
console.log(obj.property1);
|
||||
```
|
||||
|
||||
باتباع هذا المنطق ، استخدم عملية `console.log` لطباعة كل من `property1` و `property2` على الشاشة.
|
||||
|
||||
### حل:
|
||||
|
||||
`let dog = {
|
||||
name: "Spot",
|
||||
numLegs: 4
|
||||
};
|
||||
// Add your code below this line
|
||||
console.log(dog.name);
|
||||
console.log(dog.numLegs);
|
||||
`
|
||||
```javascript
|
||||
let dog = {
|
||||
name: "Spot",
|
||||
numLegs: 4
|
||||
};
|
||||
// Add your code below this line
|
||||
console.log(dog.name);
|
||||
console.log(dog.numLegs);
|
||||
```
|
@@ -8,28 +8,29 @@ localeTitle: استخدام الوراثة حتى لا تكرر نفسك
|
||||
|
||||
قم بإزالة طريقة "تناول الطعام" من Cat.prototype و Bear.prototype وأضفها إلى Animal.prototype.
|
||||
|
||||
`function Cat(name) {
|
||||
this.name = name;
|
||||
};
|
||||
|
||||
Cat.prototype = {
|
||||
constructor: Cat
|
||||
};
|
||||
|
||||
function Bear(name) {
|
||||
this.name = name;
|
||||
};
|
||||
|
||||
Bear.prototype = {
|
||||
constructor: Bear
|
||||
};
|
||||
|
||||
function Animal() { };
|
||||
|
||||
Animal.prototype = {
|
||||
constructor: Animal,
|
||||
eat: function() {
|
||||
console.log("nom nom nom");
|
||||
}
|
||||
};
|
||||
`
|
||||
```javascript
|
||||
function Cat(name) {
|
||||
this.name = name;
|
||||
};
|
||||
|
||||
Cat.prototype = {
|
||||
constructor: Cat
|
||||
};
|
||||
|
||||
function Bear(name) {
|
||||
this.name = name;
|
||||
};
|
||||
|
||||
Bear.prototype = {
|
||||
constructor: Bear
|
||||
};
|
||||
|
||||
function Animal() { };
|
||||
|
||||
Animal.prototype = {
|
||||
constructor: Animal,
|
||||
eat: function() {
|
||||
console.log("nom nom nom");
|
||||
}
|
||||
};
|
||||
```
|
@@ -10,19 +10,21 @@ localeTitle: استخدم خصائص النموذج لتخفيض قانون مك
|
||||
|
||||
#### مثال:
|
||||
|
||||
`Obj.prototype.newProperty = "New Property!";
|
||||
`
|
||||
```javascript
|
||||
Obj.prototype.newProperty = "New Property!";
|
||||
```
|
||||
|
||||
باستخدام هذا المنطق ، ببساطة إنشاء خاصية `prototype` جديد لـ `numLegs` . يمكن تمرير حالات الاختبار عن طريق استبدال كائن `Bird` بكائن `Dog` في المثال المعطى - `Bird.prototype.numLegs = 2;`
|
||||
|
||||
### حل:
|
||||
|
||||
`function Dog(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
Dog.prototype.numLegs = 4;
|
||||
|
||||
// Add your code above this line
|
||||
let beagle = new Dog("Snoopy");
|
||||
`
|
||||
```javascript
|
||||
function Dog(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
Dog.prototype.numLegs = 4;
|
||||
|
||||
// Add your code above this line
|
||||
let beagle = new Dog("Snoopy");
|
||||
```
|
@@ -10,20 +10,22 @@ localeTitle: تحقق من Constructor كائن مع instanceof
|
||||
|
||||
#### مثال:
|
||||
|
||||
`let hound = new Dog();
|
||||
`
|
||||
```javascript
|
||||
let hound = new Dog();
|
||||
```
|
||||
|
||||
تذكر أن تعطي الدالة `House` معلمة لتهيئة عدد الغرف. ثم ببساطة استدعاء العامل `instanceof` للعودة حقيقية على منزلك الجديد.
|
||||
|
||||
### حل:
|
||||
|
||||
`/* jshint expr: true */
|
||||
|
||||
function House(numBedrooms) {
|
||||
this.numBedrooms = numBedrooms;
|
||||
}
|
||||
|
||||
// Add your code below this line
|
||||
let myHouse = new House(5);
|
||||
myHouse instanceof House;
|
||||
`
|
||||
```javascript
|
||||
/* jshint expr: true */
|
||||
|
||||
function House(numBedrooms) {
|
||||
this.numBedrooms = numBedrooms;
|
||||
}
|
||||
|
||||
// Add your code below this line
|
||||
let myHouse = new House(5);
|
||||
myHouse instanceof House;
|
||||
```
|
@@ -18,7 +18,8 @@ localeTitle: استخراج مباريات
|
||||
|
||||
## حل:
|
||||
|
||||
`let extractStr = "Extract the word 'coding' from this string.";
|
||||
let codingRegex = /coding/;
|
||||
let result = extractStr.match(codingRegex);
|
||||
`
|
||||
```javascript
|
||||
let extractStr = "Extract the word 'coding' from this string.";
|
||||
let codingRegex = /coding/;
|
||||
let result = extractStr.match(codingRegex);
|
||||
```
|
@@ -10,7 +10,8 @@ localeTitle: العثور على شخصيات مع مطابقة كسول
|
||||
|
||||
#### حل:
|
||||
|
||||
`let text = "<h1>Winter is coming</h1>";
|
||||
let myRegex = /<h1>?/; // it's the answer!
|
||||
let result = text.match(myRegex);
|
||||
`
|
||||
```js
|
||||
let text = "<h1>Winter is coming</h1>";
|
||||
let myRegex = /<h1>?/; // it's the answer!
|
||||
let result = text.match(myRegex);
|
||||
```
|
@@ -18,7 +18,8 @@ localeTitle: العثور على أكثر من المباراة الأولى
|
||||
|
||||
## حل
|
||||
|
||||
`let twinkleStar = "Twinkle, twinkle, little star";
|
||||
let starRegex = /twinkle/gi;
|
||||
let result = twinkleStar.match(starRegex);
|
||||
`
|
||||
```javascript
|
||||
let twinkleStar = "Twinkle, twinkle, little star";
|
||||
let starRegex = /twinkle/gi;
|
||||
let result = twinkleStar.match(starRegex);
|
||||
```
|
@@ -21,17 +21,19 @@ localeTitle: العثور على واحد أو أكثر من المجرمين ف
|
||||
|
||||
هل تستخدم علامة "+" في تعبيرك العادي؟
|
||||
|
||||
`let regexp = /E+/; // returns E, EE, EEE patterns
|
||||
`
|
||||
```javascript
|
||||
let regexp = /E+/; // returns E, EE, EEE patterns
|
||||
```
|
||||
|
||||
### تحذير المفسد - الحل إلى الأمام
|
||||
|
||||
## حل
|
||||
|
||||
`let crowd = 'P1P2P3P4P5P6CCCP7P8P9';
|
||||
|
||||
let reCriminals = /C+/; // Change this line
|
||||
|
||||
let matchedCriminals = crowd.match(reCriminals);
|
||||
console.log(matchedCriminals);
|
||||
`
|
||||
```javascript
|
||||
let crowd = 'P1P2P3P4P5P6CCCP7P8P9';
|
||||
|
||||
let reCriminals = /C+/; // Change this line
|
||||
|
||||
let matchedCriminals = crowd.match(reCriminals);
|
||||
console.log(matchedCriminals);
|
||||
```
|
@@ -14,7 +14,8 @@ localeTitle: تجاهل حالة أثناء المطابقة
|
||||
|
||||
## حل
|
||||
|
||||
`let myString = "freeCodeCamp";
|
||||
let fccRegex = /freeCodeCamp/i;
|
||||
let result = fccRegex.test(myString);
|
||||
`
|
||||
```javascript
|
||||
let myString = "freeCodeCamp";
|
||||
let fccRegex = /freeCodeCamp/i;
|
||||
let result = fccRegex.test(myString);
|
||||
```
|
@@ -14,7 +14,8 @@ localeTitle: تطابق سلسلة حرفية مع الاحتمالات المخ
|
||||
|
||||
## حل:
|
||||
|
||||
`let petString = "James has a pet cat.";
|
||||
let petRegex = /dog|cat|bird|fish/;
|
||||
let result = petRegex.test(petString);
|
||||
`
|
||||
```javascriot
|
||||
let petString = "James has a pet cat.";
|
||||
let petRegex = /dog|cat|bird|fish/;
|
||||
let result = petRegex.test(petString);
|
||||
```
|
@@ -16,8 +16,9 @@ localeTitle: المباراة جميع غير الارقام
|
||||
|
||||
## حل
|
||||
|
||||
`let noNumRegex = /\D/g;
|
||||
`
|
||||
```javascript
|
||||
let noNumRegex = /\D/g;
|
||||
```
|
||||
|
||||
## تفسير
|
||||
|
||||
|
@@ -16,8 +16,9 @@ localeTitle: تطابق جميع الأرقام
|
||||
|
||||
## حل
|
||||
|
||||
`let numRegex = /\d/g;
|
||||
`
|
||||
```javascript
|
||||
let numRegex = /\d/g;
|
||||
```
|
||||
|
||||
## تفسير
|
||||
|
||||
|
@@ -14,10 +14,11 @@ localeTitle: تطابق أي شيء مع فترة أحرف البدل
|
||||
|
||||
## حل
|
||||
|
||||
`let exampleStr = "Let's have fun with regular expressions!";
|
||||
let unRegex = /.un/; // Change this line
|
||||
let result = unRegex.test(exampleStr);
|
||||
`
|
||||
```javascript
|
||||
let exampleStr = "Let's have fun with regular expressions!";
|
||||
let unRegex = /.un/; // Change this line
|
||||
let result = unRegex.test(exampleStr);
|
||||
```
|
||||
|
||||
## كسبلايناتيون
|
||||
|
||||
|
@@ -12,9 +12,10 @@ localeTitle: مباراة بداية أنماط سلسلة
|
||||
|
||||
جرِّب محيطك المعتاد بالأشرطة المائلة
|
||||
|
||||
`let testExp = /^test/;
|
||||
// returns true or false depending on whether test is found in the beginning of the string
|
||||
`
|
||||
```javascript
|
||||
let testExp = /^test/;
|
||||
// returns true or false depending on whether test is found in the beginning of the string
|
||||
```
|
||||
|
||||
### تلميح 2:
|
||||
|
||||
@@ -24,7 +25,8 @@ localeTitle: مباراة بداية أنماط سلسلة
|
||||
|
||||
## حل
|
||||
|
||||
`let rickyAndCal = "Cal and Ricky both like racing.";
|
||||
let calRegex = /^Cal/; // Change this line
|
||||
let result = calRegex.test(rickyAndCal);
|
||||
`
|
||||
```javascript
|
||||
let rickyAndCal = "Cal and Ricky both like racing.";
|
||||
let calRegex = /^Cal/; // Change this line
|
||||
let result = calRegex.test(rickyAndCal);
|
||||
```
|
@@ -6,22 +6,24 @@ localeTitle: مطابقة الأحرف التي تحدث Zero أو أوقات إ
|
||||
|
||||
لا يجب أن يحدث أي حرف في تعبير regex يتبعه `*` في السلسلة التي تم اختبارها ، في حين يجب أن يظهر أي حرف في تعبير regex متبوعًا بـ `+` في سلسلة واحدة على الأقل ، كما هو موضح أدناه ،
|
||||
|
||||
`let phrase = "ba humbug";
|
||||
|
||||
let regexPlus = /bah+/;
|
||||
let regexStar = /bah*/;
|
||||
|
||||
regexPlus.test(phrase); // returns false
|
||||
regexStar.test(phrase); // returns true
|
||||
`
|
||||
```javascript
|
||||
let phrase = "ba humbug";
|
||||
|
||||
let regexPlus = /bah+/;
|
||||
let regexStar = /bah*/;
|
||||
|
||||
regexPlus.test(phrase); // returns false
|
||||
regexStar.test(phrase); // returns true
|
||||
```
|
||||
|
||||
كلاهما يسمحان بأي عدد من الأحداث من نفس الحرف في صف ، على سبيل المثال ،
|
||||
|
||||
`let phrase = "wooooow look at that!";
|
||||
|
||||
let regexPlus = /wo+w/;
|
||||
let regexStar = /wo*w/;
|
||||
|
||||
regexPlus.test(phrase); // returns true
|
||||
regexStar.test(phrase); // returns true
|
||||
`
|
||||
```javascript
|
||||
let phrase = "wooooow look at that!";
|
||||
|
||||
let regexPlus = /wo+w/;
|
||||
let regexStar = /wo*w/;
|
||||
|
||||
regexPlus.test(phrase); // returns true
|
||||
regexStar.test(phrase); // returns true
|
||||
```
|
@@ -16,7 +16,8 @@ localeTitle: المباراة الحرفيه الاوتار
|
||||
|
||||
## حل:
|
||||
|
||||
`let waldoIsHiding = "Somewhere Waldo is hiding in this text.";
|
||||
let waldoRegex = /Waldo/; // Change this line
|
||||
let result = waldoRegex.test(waldoIsHiding);
|
||||
`
|
||||
```javascript
|
||||
let waldoIsHiding = "Somewhere Waldo is hiding in this text.";
|
||||
let waldoRegex = /Waldo/; // Change this line
|
||||
let result = waldoRegex.test(waldoIsHiding);
|
||||
```
|
@@ -21,16 +21,18 @@ localeTitle: أرقام المباراة ورسائل الأبجدية
|
||||
|
||||
هل تذكر تمكين إشارات regexp مثل "i" لتجاهل الحالة و "g" لإرجاع قيم متعددة؟ إذا كان الأمر كذلك ، فهل تقوم بتضمين كل من مطابقة الأحرف للأرقام والحروف؟
|
||||
|
||||
`let regexp = /[a-z1-100]/ig
|
||||
// above code returns all characters from A to Z, along with all numbers from 1 to 100
|
||||
// this includes the letter A and Z and the numbers 1 and 100
|
||||
`
|
||||
```javascript
|
||||
let regexp = /[a-z1-100]/ig
|
||||
// above code returns all characters from A to Z, along with all numbers from 1 to 100
|
||||
// this includes the letter A and Z and the numbers 1 and 100
|
||||
```
|
||||
|
||||
### تنبيه المفسد - الحل إلى الأمام
|
||||
|
||||
## حل
|
||||
|
||||
`let quoteSample = "Blueberry 3.141592653s are delicious.";
|
||||
let myRegex = /[h-s2-6]/ig; // Change this line
|
||||
let result = quoteSample.match(myRegex); // Change this line
|
||||
`
|
||||
```javascript
|
||||
let quoteSample = "Blueberry 3.141592653s are delicious.";
|
||||
let myRegex = /[h-s2-6]/ig; // Change this line
|
||||
let result = quoteSample.match(myRegex); // Change this line
|
||||
```
|
@@ -20,7 +20,8 @@ localeTitle: تطابق شخصية واحدة مع إمكانيات متعددة
|
||||
|
||||
## حل
|
||||
|
||||
`let quoteSample = "Beware of bugs in the above code; I have only proved it correct, not tried it.";
|
||||
let vowelRegex = /[aeiou]/ig; // Change this line
|
||||
let result = quoteSample.match(vowelRegex); // Change this line
|
||||
`
|
||||
```javascript
|
||||
let quoteSample = "Beware of bugs in the above code; I have only proved it correct, not tried it.";
|
||||
let vowelRegex = /[aeiou]/ig; // Change this line
|
||||
let result = quoteSample.match(vowelRegex); // Change this line
|
||||
```
|
@@ -23,14 +23,16 @@ localeTitle: مطابقة أحرف مفردة غير محددة
|
||||
|
||||
تأكد من التحقق مما إذا كان نطاق الأرقام صحيحًا - يطالبنا التحدي بإنهاء جميع الأرقام من 0 إلى 99. يمكن القيام بذلك باستخدام علامة الإبطال السلبي الموضوعة مباشرة بعد أول شريحة افتتاحية من كلمة regexp الخاصة بك.
|
||||
|
||||
`let numbersRegExp = /[^0-99]/ig;
|
||||
`
|
||||
```javacsript
|
||||
let numbersRegExp = /[^0-99]/ig;
|
||||
```
|
||||
|
||||
### تنبيه المفسد - الحل إلى الأمام
|
||||
|
||||
## حل
|
||||
|
||||
`let quoteSample = "3 blind mice.";
|
||||
let myRegex = /[^aeiou^0-99]/ig; // Change this line
|
||||
let result = quoteSample.match(myRegex); // Change this line
|
||||
`
|
||||
```javascript
|
||||
let quoteSample = "3 blind mice.";
|
||||
let myRegex = /[^aeiou^0-99]/ig; // Change this line
|
||||
let result = quoteSample.match(myRegex); // Change this line
|
||||
```
|
@@ -11,7 +11,8 @@ localeTitle: الإيجابية و السلبية Lookahead
|
||||
|
||||
## حل :
|
||||
|
||||
`let sampleWord = "astronaut";
|
||||
let pwRegex = /(?=\w{5,})(?=\D*\d{2})/;
|
||||
let result = pwRegex.test(sampleWord);
|
||||
`
|
||||
```javascript
|
||||
let sampleWord = "astronaut";
|
||||
let pwRegex = /(?=\w{5,})(?=\D*\d{2})/;
|
||||
let result = pwRegex.test(sampleWord);
|
||||
```
|
@@ -18,7 +18,8 @@ localeTitle: إزالة Whitespace من البداية والنهاية
|
||||
|
||||
## حل:
|
||||
|
||||
`let hello = " Hello, World! ";
|
||||
let wsRegex = /^\s+|\s+$/g; // Change this line
|
||||
let result = hello.replace(wsRegex, ''); // Change this line
|
||||
`
|
||||
```javascript
|
||||
let hello = " Hello, World! ";
|
||||
let wsRegex = /^\s+|\s+$/g; // Change this line
|
||||
let result = hello.replace(wsRegex, ''); // Change this line
|
||||
```
|
@@ -15,13 +15,15 @@ localeTitle: تقييد أسماء المستخدمين المحتملين
|
||||
|
||||
1. الأرقام الوحيدة في اسم المستخدم يجب أن تكون في النهاية. `\d$` يمكن أن يكون هناك صفر أو أكثر منهم في النهاية. `*`
|
||||
|
||||
`/\d*$/;
|
||||
`
|
||||
```javascript
|
||||
/\d*$/;
|
||||
```
|
||||
|
||||
2. يمكن أن تكون أحرف اسم المستخدم صغيرة وأحرف كبيرة. `i`
|
||||
|
||||
`/\d*$/i;
|
||||
`
|
||||
```javascript
|
||||
/\d*$/i;
|
||||
```
|
||||
|
||||
3. يجب أن تتكون أسماء المستخدمين من حرفين على الأقل. `{2,}` يمكن لاسم المستخدم المكون من حرفين فقط استخدام أحرف الحروف الأبجدية. `^[az]`
|
||||
|
||||
|
@@ -8,10 +8,11 @@ localeTitle: إعادة استخدام الأنماط باستخدام مجمو
|
||||
|
||||
كود المقدمة أدناه:
|
||||
|
||||
`let testString = "test test test ";
|
||||
let reRegex =/(test)\s\1/;
|
||||
let result = reRegex.test(testString);
|
||||
`
|
||||
```javascript
|
||||
let testString = "test test test ";
|
||||
let reRegex =/(test)\s\1/;
|
||||
let result = reRegex.test(testString);
|
||||
```
|
||||
|
||||
سوف تتطابق `result` مع `test test` فقط لأن `\1` في هذا المثال تشير إلى نفس النص الذي تم مؤخرًا تطابقه مع المجموعة الأولى `(test)` .
|
||||
|
||||
@@ -27,10 +28,11 @@ localeTitle: إعادة استخدام الأنماط باستخدام مجمو
|
||||
|
||||
نظرا للرمز أدناه:
|
||||
|
||||
`let testString = "test test test ";
|
||||
let reRegex =/(test)(\s)\1\2\1/;
|
||||
let result = reRegex.test(testString);
|
||||
`
|
||||
```javascript
|
||||
let testString = "test test test ";
|
||||
let reRegex =/(test)(\s)\1\2\1/;
|
||||
let result = reRegex.test(testString);
|
||||
```
|
||||
|
||||
سيطابق `test test test` كامل `test test test` بسبب: `\1` يكرر (اختبار) `\2` يكرر (\\ s)
|
||||
|
||||
@@ -38,10 +40,11 @@ localeTitle: إعادة استخدام الأنماط باستخدام مجمو
|
||||
|
||||
الكود أدناه:
|
||||
|
||||
`let testString = "test test test test test test";
|
||||
let reRegex =/(test)(\s)\1\2\1/g;
|
||||
let result = reRegex.test(testString);
|
||||
`
|
||||
```javascript
|
||||
let testString = "test test test test test test";
|
||||
let reRegex =/(test)(\s)\1\2\1/g;
|
||||
let result = reRegex.test(testString);
|
||||
```
|
||||
|
||||
نظرًا لأننا استخدمنا `\g` ، فلن يعود التعبير المعتاد الخاص بنا بعد أول مباراة كاملة ( `test test test` ) ويطابق كل التكرار.
|
||||
|
||||
@@ -49,7 +52,8 @@ localeTitle: إعادة استخدام الأنماط باستخدام مجمو
|
||||
|
||||
## حل:
|
||||
|
||||
`let repeatNum = "42 42 42";
|
||||
let reRegex = /^(\d+)\s\1\s\1$/;
|
||||
let result = reRegex.test(repeatNum);
|
||||
`
|
||||
```javascript
|
||||
let repeatNum = "42 42 42";
|
||||
let reRegex = /^(\d+)\s\1\s\1$/;
|
||||
let result = reRegex.test(repeatNum);
|
||||
```
|
||||
|
@@ -8,15 +8,16 @@ localeTitle: تحديد العلوي والسفلي عدد من المباريا
|
||||
|
||||
كل هذه السلاسل ستعود `true` :
|
||||
|
||||
`let threeAs = "aaa";
|
||||
let fourAs = "aaaa";
|
||||
let sevenAs = "aaaaaaa";
|
||||
|
||||
let myRegex = /a{2,4}/;
|
||||
myRegex.test(threeAs) ; // true
|
||||
myRegex.test(fourAs) ; // true
|
||||
myRegex.test(sevenAs) ; // true
|
||||
`
|
||||
```javascript
|
||||
let threeAs = "aaa";
|
||||
let fourAs = "aaaa";
|
||||
let sevenAs = "aaaaaaa";
|
||||
|
||||
let myRegex = /a{2,4}/;
|
||||
myRegex.test(threeAs) ; // true
|
||||
myRegex.test(fourAs) ; // true
|
||||
myRegex.test(sevenAs) ; // true
|
||||
```
|
||||
|
||||
## Spolier Alert!
|
||||
|
||||
@@ -24,7 +25,8 @@ localeTitle: تحديد العلوي والسفلي عدد من المباريا
|
||||
|
||||
## حل:
|
||||
|
||||
`let ohStr = "Ohhh no";
|
||||
let ohRegex = /Oh{3,6}\sno/; // Change this line
|
||||
let result = ohRegex.test(ohStr);
|
||||
`
|
||||
```javascript
|
||||
let ohStr = "Ohhh no";
|
||||
let ohRegex = /Oh{3,6}\sno/; // Change this line
|
||||
let result = ohRegex.test(ohStr);
|
||||
```
|
@@ -14,8 +14,9 @@ localeTitle: استخدم مجموعات الالتقاط للبحث واستب
|
||||
|
||||
## حل
|
||||
|
||||
`let huhText = "This sandwich is good.";
|
||||
let fixRegex = /good/; // Change this line
|
||||
let replaceText = "okey-dokey"; // Change this line
|
||||
let result = huhText.replace(fixRegex, replaceText);
|
||||
`
|
||||
```javascript
|
||||
let huhText = "This sandwich is good.";
|
||||
let fixRegex = /good/; // Change this line
|
||||
let replaceText = "okey-dokey"; // Change this line
|
||||
let result = huhText.replace(fixRegex, replaceText);
|
||||
```
|
@@ -14,7 +14,8 @@ localeTitle: باستخدام طريقة الاختبار
|
||||
|
||||
## حل
|
||||
|
||||
`let myString = "Hello, World!";
|
||||
let myRegex = /Hello/;
|
||||
let result = myRegex.test(myString); // Change this line
|
||||
`
|
||||
```javascript
|
||||
let myString = "Hello, World!";
|
||||
let myRegex = /Hello/;
|
||||
let result = myRegex.test(myString); // Change this line
|
||||
```
|
Reference in New Issue
Block a user