diff --git a/curriculum/challenges/arabic/01-responsive-web-design/responsive-web-design-projects/build-a-survey-form.md b/curriculum/challenges/arabic/01-responsive-web-design/responsive-web-design-projects/build-a-survey-form.md index 247fb17e35b..8a1b20bb375 100644 --- a/curriculum/challenges/arabic/01-responsive-web-design/responsive-web-design-projects/build-a-survey-form.md +++ b/curriculum/challenges/arabic/01-responsive-web-design/responsive-web-design-projects/build-a-survey-form.md @@ -119,7 +119,7 @@ const el = document.getElementById('email') assert(!!el && el.required) ``` -Your `#email` should be a descendant of `#survey-form` +Your `#email` should be a descendant of `#survey-form`. ```js const el = document.querySelector('#survey-form #email') diff --git a/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-nested-objects.md b/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-nested-objects.md index b1a3078336b..084e7c9f464 100644 --- a/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-nested-objects.md +++ b/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-nested-objects.md @@ -53,7 +53,7 @@ assert( ```js assert( code.match( - /(var|const|let)\s*{\s*today\s*:\s*{\s*(low\s*:\s*lowToday[^}]*|[^,]*,\s*low\s*:\s*lowToday\s*)}\s*}\s*=\s*LOCAL_FORECAST(;|\s+|\/\/)/g + /(var|const|let)\s*{\s*today\s*:\s*{\s*(low\s*:\s*lowToday[^}]*|[^,]*,\s*low\s*:\s*lowToday\s*)},?\s*}\s*=\s*LOCAL_FORECAST(;|\s+|\/\/)/g ) ); ``` @@ -63,7 +63,7 @@ assert( ```js assert( code.match( - /(var|const|let)\s*{\s*today\s*:\s*{\s*(high\s*:\s*highToday[^}]*|[^,]*,\s*high\s*:\s*highToday\s*)}\s*}\s*=\s*LOCAL_FORECAST(;|\s+|\/\/)/g + /(var|const|let)\s*{\s*today\s*:\s*{\s*(high\s*:\s*highToday[^}]*|[^,]*,\s*high\s*:\s*highToday,?\s*)},?\s*}\s*=\s*LOCAL_FORECAST(;|\s+|\/\/)/g ) ); ``` diff --git a/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-128-hexagonal-tile-differences.md b/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-128-hexagonal-tile-differences.md index 7e8bea5482e..49d59948762 100644 --- a/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-128-hexagonal-tile-differences.md +++ b/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-128-hexagonal-tile-differences.md @@ -56,46 +56,57 @@ hexagonalTile(10); # --solutions-- ```js -const NUM_PRIMES = 840000; -const PRIME_SEIVE = Array(Math.floor((NUM_PRIMES-1)/2)).fill(true); -(function initPrimes(num) { - const upper = Math.floor((num - 1) / 2); - const sqrtUpper = Math.floor((Math.sqrt(num) - 1) / 2); - for (let i = 0; i <= sqrtUpper; i++) { - if (PRIME_SEIVE[i]) { - // Mark value in PRIMES array - const prime = 2 * i + 3; - // Mark all multiples of this number as false (not prime) - const primeSqaredIndex = 2 * i ** 2 + 6 * i + 3; - for (let j = primeSqaredIndex; j < upper; j += prime) { - PRIME_SEIVE[j] = false; +class PrimeSeive { + constructor(num) { + const seive = Array(Math.floor((num - 1) / 2)).fill(true); + const upper = Math.floor((num - 1) / 2); + const sqrtUpper = Math.floor((Math.sqrt(num) - 1) / 2); + + for (let i = 0; i <= sqrtUpper; i++) { + if (seive[i]) { + // Mark value in seive array + const prime = 2 * i + 3; + // Mark all multiples of this number as false (not prime) + const primeSqaredIndex = 2 * i ** 2 + 6 * i + 3; + for (let j = primeSqaredIndex; j < upper; j += prime) { + seive[j] = false; + } } } - } -})(NUM_PRIMES); -function isPrime(num) { - if (num === 2) return true; - else if (num % 2 === 0) return false - else return PRIME_SEIVE[(num - 3) / 2]; -} + this._seive = seive; + } + + isPrime(num) { + return num === 2 + ? true + : num % 2 === 0 + ? false + : this.isOddPrime(num); + } + + isOddPrime(num) { + return this._seive[(num - 3) / 2]; + } +}; function hexagonalTile(tileIndex) { + const primeSeive = new PrimeSeive(tileIndex * 420); let count = 1; let n = 1; let number = 0; while (count < tileIndex) { - if (isPrime(6*n - 1) && - isPrime(6*n + 1) && - isPrime(12*n + 5)) { + if (primeSeive.isPrime(6*n - 1) && + primeSeive.isPrime(6*n + 1) && + primeSeive.isPrime(12*n + 5)) { number = 3*n*n - 3*n + 2; count++; if (count >= tileIndex) break; } - if (isPrime(6*n + 5) && - isPrime(6*n - 1) && - isPrime(12*n - 7) && n != 1) { + if (primeSeive.isPrime(6*n + 5) && + primeSeive.isPrime(6*n - 1) && + primeSeive.isPrime(12*n - 7) && n != 1) { number = 3*n*n + 3*n + 1; count++; } diff --git a/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-47-distinct-primes-factors.md b/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-47-distinct-primes-factors.md index 978b7affd9b..3b79403a4ea 100644 --- a/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-47-distinct-primes-factors.md +++ b/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-47-distinct-primes-factors.md @@ -67,25 +67,28 @@ distinctPrimeFactors(4, 4); # --solutions-- ```js -// Initalize factor count with seive -const NUMFACTORS = Array(135000).fill(0); -(function initFactors(num) { - for (let i = 2; i < num; i++) - if (NUMFACTORS[i] === 0) - for (let j = i; j < num; j += i) - NUMFACTORS[j]++; -})(135000); - function distinctPrimeFactors(targetNumPrimes, targetConsecutive) { + const primeLimit = targetNumPrimes * targetConsecutive * 10000; + const numFactors = Array(primeLimit).fill(0); + let numConsecutive = 0; - let currNumber = 10; - while (numConsecutive < targetConsecutive) { - if (NUMFACTORS[currNumber] === targetNumPrimes) + for (let i = 2; i < primeLimit; i++) { + if (numFactors[i] === targetNumPrimes) { + // Current number is composite with target num factors numConsecutive++; - else + if (numConsecutive === targetConsecutive) { + return i - numConsecutive + 1; + } + } else { + // Current number is not matching composite numConsecutive = 0; - currNumber++; + if (numFactors[i] === 0) { + // Current number is prime + for (let j = i; j < primeLimit; j += i) { + numFactors[j]++; + } + } + } } - return currNumber - targetConsecutive; } ``` diff --git a/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-50-consecutive-prime-sum.md b/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-50-consecutive-prime-sum.md index 861a3e99a8e..7cd5bc67b14 100644 --- a/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-50-consecutive-prime-sum.md +++ b/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-50-consecutive-prime-sum.md @@ -54,40 +54,56 @@ consecutivePrimeSum(1000000); # --solutions-- ```js -// Initalize prime number list with sieve -const NUM_PRIMES = 1000000; -const PRIMES = [2]; -const PRIME_SIEVE = Array(Math.floor((NUM_PRIMES-1)/2)).fill(true); -(function initPrimes(num) { - const upper = Math.floor((num - 1) / 2); - const sqrtUpper = Math.floor((Math.sqrt(num) - 1) / 2); - for (let i = 0; i <= sqrtUpper; i++) { - if (PRIME_SIEVE[i]) { - // Mark value in PRIMES array - const prime = 2 * i + 3; - PRIMES.push(prime); - // Mark all multiples of this number as false (not prime) - const primeSqaredIndex = 2 * i ** 2 + 6 * i + 3; - for (let j = primeSqaredIndex; j < upper; j += prime) - PRIME_SIEVE[j] = false; - } - } - for (let i = sqrtUpper + 1; i < upper; i++) { - if (PRIME_SIEVE[i]) - PRIMES.push(2 * i + 3); - } -})(NUM_PRIMES); +class PrimeSeive { + constructor(num) { + const seive = Array(Math.floor((num - 1) / 2)).fill(true); + const primes = [2]; + const upper = Math.floor((num - 1) / 2); + const sqrtUpper = Math.floor((Math.sqrt(num) - 1) / 2); -function isPrime(num) { - if (num === 2) - return true; - else if (num % 2 === 0) - return false - else - return PRIME_SIEVE[(num - 3) / 2]; -} + for (let i = 0; i <= sqrtUpper; i++) { + if (seive[i]) { + // Mark value in seive array + const prime = 2 * i + 3; + primes.push(prime); + // Mark all multiples of this number as false (not prime) + const primeSqaredIndex = 2 * i ** 2 + 6 * i + 3; + for (let j = primeSqaredIndex; j < upper; j += prime) { + seive[j] = false; + } + } + } + for (let i = sqrtUpper + 1; i < upper; i++) { + if (seive[i]) { + primes.push(2 * i + 3); + } + } + + this._seive = seive; + this._primes = primes; + } + + isPrime(num) { + return num === 2 + ? true + : num % 2 === 0 + ? false + : this.isOddPrime(num); + } + + isOddPrime(num) { + return this._seive[(num - 3) / 2]; + } + + get primes() { + return this._primes; + } +}; function consecutivePrimeSum(limit) { + // Initalize seive + const primeSeive = new PrimeSeive(limit); + // Initalize for longest sum < 100 let bestPrime = 41; let bestI = 0; @@ -102,20 +118,20 @@ function consecutivePrimeSum(limit) { // -- Loop while pushing j towards end of PRIMES list // keeping sum under limit while (currSum < limit) { - if (isPrime(currSum)) { + if (primeSeive.isPrime(currSum)) { bestPrime = sumOfCurrRange = currSum; bestI = i; bestJ = j; } // -- Increment inner loop j++; - currSum += PRIMES[j]; + currSum += primeSeive.primes[j]; } // -- Increment outer loop i++; j = i + (bestJ - bestI); - sumOfCurrRange -= PRIMES[i - 1]; - sumOfCurrRange += PRIMES[j]; + sumOfCurrRange -= primeSeive.primes[i - 1]; + sumOfCurrRange += primeSeive.primes[j]; } // Return return bestPrime; diff --git a/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-51-prime-digit-replacements.md b/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-51-prime-digit-replacements.md index 26aed0ce89a..cdbfc3e568b 100644 --- a/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-51-prime-digit-replacements.md +++ b/curriculum/challenges/arabic/10-coding-interview-prep/project-euler/problem-51-prime-digit-replacements.md @@ -56,31 +56,43 @@ primeDigitReplacements(6); # --solutions-- ```js -const NUM_PRIMES = 1000000; -const PRIME_SEIVE = Array(Math.floor((NUM_PRIMES-1)/2)).fill(true); -(function initPrimes(num) { - const upper = Math.floor((num - 1) / 2); - const sqrtUpper = Math.floor((Math.sqrt(num) - 1) / 2); - for (let i = 0; i <= sqrtUpper; i++) { - if (PRIME_SEIVE[i]) { - // Mark value in PRIMES array - const prime = 2 * i + 3; - // Mark all multiples of this number as false (not prime) - const primeSqaredIndex = 2 * i ** 2 + 6 * i + 3; - for (let j = primeSqaredIndex; j < upper; j += prime) { - PRIME_SEIVE[j] = false; +class PrimeSeive { + constructor(num) { + const seive = Array(Math.floor((num - 1) / 2)).fill(true); + const upper = Math.floor((num - 1) / 2); + const sqrtUpper = Math.floor((Math.sqrt(num) - 1) / 2); + + for (let i = 0; i <= sqrtUpper; i++) { + if (seive[i]) { + // Mark value in seive array + const prime = 2 * i + 3; + // Mark all multiples of this number as false (not prime) + const primeSqaredIndex = 2 * i ** 2 + 6 * i + 3; + for (let j = primeSqaredIndex; j < upper; j += prime) { + seive[j] = false; + } } } - } -})(NUM_PRIMES); -function isPrime(num) { - if (num === 2) return true; - else if (num % 2 === 0) return false - else return PRIME_SEIVE[(num - 3) / 2]; -} + this._seive = seive; + } + + isPrime(num) { + return num === 2 + ? true + : num % 2 === 0 + ? false + : this.isOddPrime(num); + } + + isOddPrime(num) { + return this._seive[(num - 3) / 2]; + } +}; function primeDigitReplacements(n) { + const primeSeive = new PrimeSeive(n * n * n * 2000); + function isNFamily(number, n) { const prime = number.toString(); const lastDigit = prime[prime.length - 1]; @@ -114,12 +126,12 @@ function primeDigitReplacements(n) { function isPartOfFamily(number, prime) { return ( - isPrime(number) && number.toString().length === prime.length + primeSeive.isPrime(number) && number.toString().length === prime.length ); } for (let number = 1; number < 125000; number++) { - if (isPrime(number) && isNFamily(number, n)) { + if (primeSeive.isPrime(number) && isNFamily(number, n)) { return number; } } diff --git a/curriculum/challenges/arabic/14-responsive-web-design-22/build-a-survey-form-project/build-a-survey-form.md b/curriculum/challenges/arabic/14-responsive-web-design-22/build-a-survey-form-project/build-a-survey-form.md index ce6adc7cda6..87edd2d2956 100644 --- a/curriculum/challenges/arabic/14-responsive-web-design-22/build-a-survey-form-project/build-a-survey-form.md +++ b/curriculum/challenges/arabic/14-responsive-web-design-22/build-a-survey-form-project/build-a-survey-form.md @@ -119,7 +119,7 @@ const el = document.getElementById('email') assert(!!el && el.required) ``` -يجب أن يكون `#email` الخاص بك فرع من `#survey-form` +Your `#email` should be a descendant of `#survey-form`. ```js const el = document.querySelector('#survey-form #email') diff --git a/curriculum/challenges/arabic/14-responsive-web-design-22/learn-css-flexbox-by-building-a-photo-gallery/61537c9eecea6a335db6da79.md b/curriculum/challenges/arabic/14-responsive-web-design-22/learn-css-flexbox-by-building-a-photo-gallery/61537c9eecea6a335db6da79.md index 472e09d230d..03ac09c5a62 100644 --- a/curriculum/challenges/arabic/14-responsive-web-design-22/learn-css-flexbox-by-building-a-photo-gallery/61537c9eecea6a335db6da79.md +++ b/curriculum/challenges/arabic/14-responsive-web-design-22/learn-css-flexbox-by-building-a-photo-gallery/61537c9eecea6a335db6da79.md @@ -7,7 +7,7 @@ dashedName: step-5 # --description-- -Below your `.header` element, create a new `div` element and assign it a `class` of `gallery`. سيكون `div` حاوية لصور المَعْرِض. +أسفل عنصرك `.header`، أنشئ عنصر `div` جديد مع `class` يسمى `gallery`. سيكون `div` حاوية لصور المَعْرِض. في عنصر `.gallery`، أنشئ تسع عناصر `img`. diff --git a/curriculum/challenges/arabic/14-responsive-web-design-22/learn-css-variables-by-building-a-city-skyline/5d822fd413a79914d39e98d5.md b/curriculum/challenges/arabic/14-responsive-web-design-22/learn-css-variables-by-building-a-city-skyline/5d822fd413a79914d39e98d5.md index 8af55362cd3..955754aeda8 100644 --- a/curriculum/challenges/arabic/14-responsive-web-design-22/learn-css-variables-by-building-a-city-skyline/5d822fd413a79914d39e98d5.md +++ b/curriculum/challenges/arabic/14-responsive-web-design-22/learn-css-variables-by-building-a-city-skyline/5d822fd413a79914d39e98d5.md @@ -7,7 +7,7 @@ dashedName: step-13 # --description-- -Center the parts of your building by turning the `.bb1` element into a flexbox parent. Use the `flex-direction` and `align-items` properties to center the children. +ضع أجزاء مبناك بالمنتصف بتغير عنصر `.bb1` إلى عنصر حاوي بتركيب flexbox. استخدم خصائص `flex-direction` و `align-items` لوضع العنصر الفرعي. # --hints-- diff --git a/curriculum/challenges/arabic/14-responsive-web-design-22/learn-css-variables-by-building-a-city-skyline/5d822fd413a79914d39e98de.md b/curriculum/challenges/arabic/14-responsive-web-design-22/learn-css-variables-by-building-a-city-skyline/5d822fd413a79914d39e98de.md index 3f03a524e45..6543a8e156f 100644 --- a/curriculum/challenges/arabic/14-responsive-web-design-22/learn-css-variables-by-building-a-city-skyline/5d822fd413a79914d39e98de.md +++ b/curriculum/challenges/arabic/14-responsive-web-design-22/learn-css-variables-by-building-a-city-skyline/5d822fd413a79914d39e98de.md @@ -7,7 +7,7 @@ dashedName: step-22 # --description-- -إنشاء مُتغير جديد أسفل المُتغير الآخر يسمى `--building-color2` وإعطائه قيمة `#66cc99`. ثم عيّنها كخاصية `background-color` لعنصر `.bb2`. +Create a new variable below your `--building-color1` variable. Name your new variable `--building-color2` and give it a value of `#66cc99`. Then set it as the `background-color` of `.bb2`. # --hints-- @@ -17,7 +17,7 @@ dashedName: step-22 assert.exists(new __helpers.CSSHelp(document).isPropertyUsed('--building-color2')); ``` -يجب عليك إعطاء `--building-color2` قيمة `#66cc99`. +You should give `--building-color2` a value of `#66cc99` within the `.bb1` class. ```js assert.equal(new __helpers.CSSHelp(document).getStyle('.bb1')?.getPropertyValue('--building-color2').trim(), '#66cc99'); diff --git a/curriculum/challenges/arabic/14-responsive-web-design-22/learn-html-by-building-a-cat-photo-app/5ef9b03c81a63668521804dc.md b/curriculum/challenges/arabic/14-responsive-web-design-22/learn-html-by-building-a-cat-photo-app/5ef9b03c81a63668521804dc.md index 1240152dffb..04d45767cf2 100644 --- a/curriculum/challenges/arabic/14-responsive-web-design-22/learn-html-by-building-a-cat-photo-app/5ef9b03c81a63668521804dc.md +++ b/curriculum/challenges/arabic/14-responsive-web-design-22/learn-html-by-building-a-cat-photo-app/5ef9b03c81a63668521804dc.md @@ -51,7 +51,17 @@ assert( assert($('input')[0].hasAttribute('type')); ``` -عنصر `input` الخاص بك يجب أن يحتوي على سمة `type` بقيمة `radio`. إما أنك حذفت القيمة أو لديك خطأ إملائي. تذكر أن قيم السمة يجب أن تكون محاطة بعلامات اقتباس. +Your new `input` element should have only one `type` attribute. Remove any extras. + +```js +assert($('input')[0] + .getAttributeNames() + .filter(attr => attr === 'type') + .length === 1 +); +``` + +Your new `input` element should have a `type` attribute with the value `radio`. You have either omitted the value or have a typo. Remember that attribute values should be surrounded with quotation marks. ```js assert( @@ -61,20 +71,20 @@ assert( ); ``` -على الرغم من أنك قمت بتعيين عنصر `input` سمة `type` إلى `radio`، يوصى بأن تحيط دائما قيمة السمة بعلامات اقتباس. +Although you have set the new `input` element's `type` attribute to `radio`, it is recommended to always surround the value of an attribute with quotation marks. ```js assert(!/\<\s*input\s+type\s*=\s*radio/i.test(code)); ``` -يجب أن يتواجد النص `Indoor` لزر الـ `radio`، بعد الرز وليس قبله. +The `radio` button's `Indoor` text should be located after it instead of before it. ```js const radioInputElem = $('input')[0]; assert(!radioInputElem.previousSibling.nodeValue.match(/Indoor/i)); ``` -النص `Indoor` يجب أن يكون مباشرة على يمين زر الـ `radio`. إما أنك حذفت النص أو لديك خطأ إملائي. +The text `Indoor` should be located directly to the right of your `radio` button. You have either omitted the text or have a typo. ```js const radioInputElem = $('input')[0]; @@ -125,6 +135,7 @@ assert(