Skip to content

Commit ab4bfdf

Browse files
authored
New question addition Q10, Q24
1 parent dc583cd commit ab4bfdf

File tree

1 file changed

+83
-41
lines changed

1 file changed

+83
-41
lines changed

challenges/primitives.md

Lines changed: 83 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,29 @@
1313
7. [Show the frequently and commonly used methods available on `Number` object with coding examples](#Q7)
1414
8. [Write the polyfill for `Number.isNaN`](#Q8)
1515
9. [Show the frequently and commonly used methods available on `Math` object with coding examples](#Q9)
16-
10. [Create a function which returns a random number in the given range of values both inclusive](#Q10)
17-
11. [How can we solve the problem of comparision of 0.1 + 0.2 with 0.3 where `===` operator fails](#Q11)
18-
12. [Write a code to iterate over a string](#Q12)
19-
13. [Write a program to reverse a string](#Q13)
20-
14. [Write a program to reverse a string by words. Also show the reverse of each words in place](#Q14)
21-
15. [Write a program to reverse a given integer number](#Q15)
22-
16. [Write a code to replace all the spaces of the string with underscores](#Q16)
23-
17. [Write a function which can convert the time input given in 12 hours format to 24 hours format](#Q17)
24-
18. [Write a function which accepts a string argument and returns the count of characters between the first and last character 'X'](#Q18)
25-
19. [Write a function to truncate a string to a certain number of letters](#Q19)
26-
20. [Write a code to truncate a string to a certain number of words](#Q20)
27-
21. [Show the creation of Regular Expression in JavaScript](#Q21)
28-
22. [Create a regular expression to validate if the given input is valid Indian mobile number or not](#Q22)
29-
23. [Write a function which checks if a given search text is present either in the beginning of the first name or the second name](#Q23)
30-
24. [Write a function to chop a string into chunks of a given length and return it as array](#Q24)
31-
25. [Write a code to remove all the vowels from a given string](#Q25)
32-
26. [Create a function which returns random hex color code](#Q26)
33-
27. [Write a function which accepts two valid dates and returns the difference between them as number of days](#Q27)
34-
28. [Show the usage of template literals, expression interpolation and tagged templates](#Q28)
35-
29. [Write a code to show the working of `try...catch...finally`](#Q29)
36-
30. [Show the creation and usage of `symbol` with code](#Q30)
16+
10. [Write a function which returns true if given value of number is an integer without using any inbuilt functions](#Q10)
17+
11. [Create a function which returns a random number in the given range of values both inclusive](#Q11)
18+
12. [How can we solve the problem of comparision of 0.1 + 0.2 with 0.3 where `===` operator fails](#Q12)
19+
13. [Write a code to iterate over a string](#Q13)
20+
14. [Write a program to reverse a string](#Q14)
21+
15. [Write a program to reverse a string by words. Also show the reverse of each words in place](#Q15)
22+
16. [Write a program to reverse a given integer number](#Q16)
23+
17. [Write a code to replace all the spaces of the string with underscores](#Q17)
24+
18. [Write a function which can convert the time input given in 12 hours format to 24 hours format](#Q18)
25+
19. [Write a function which accepts a string argument and returns the count of characters between the first and last character 'X'](#Q19)
26+
20. [Write a function to truncate a string to a certain number of letters](#Q20)
27+
21. [Write a code to truncate a string to a certain number of words](#Q21)
28+
22. [Show the creation of Regular Expression in JavaScript](#Q22)
29+
23. [Create a regular expression to validate if the given input is valid Indian mobile number or not](#Q23)
30+
24. [Write a function which returns a list of elements which contains at least one character as digit](#Q24)
31+
25. [Write a function which checks if a given search text is present either in the beginning of the first name or the second name](#Q25)
32+
26. [Write a function to chop a string into chunks of a given length and return it as array](#Q26)
33+
27. [Write a code to remove all the vowels from a given string](#Q27)
34+
28. [Create a function which returns random hex color code](#Q28)
35+
29. [Write a function which accepts two valid dates and returns the difference between them as number of days](#Q29)
36+
30. [Show the usage of template literals, expression interpolation and tagged templates](#Q30)
37+
31. [Write a code to show the working of `try...catch...finally`](#Q31)
38+
32. [Show the creation and usage of `symbol` with code](#Q32)
3739

3840
---
3941

@@ -322,6 +324,24 @@ Math.trunc(-6.3)); // -6
322324
<br />
323325
324326
#### Q10
327+
### Write a function which returns true if given value of number is an integer without using any inbuilt functions
328+
```js
329+
// Example
330+
isInt(4.0); // true
331+
isInt(12.2); // false
332+
isInt(0.3); // false
333+
```
334+
- Modulo operator can be used to check if there is a remainder left when divided by 1
335+
336+
```js
337+
function isInt(value){
338+
return value % 1 === 0;
339+
}
340+
```
341+
342+
<br />
343+
344+
#### Q11
325345
### Create a function which returns a random number in the given range of values both inclusive
326346
327347
- `Math.random` function returns a floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive)
@@ -342,7 +362,7 @@ Usage of `Math.round` depends on the logic used to accomplish the requirement
342362
343363
<br />
344364
345-
#### Q11
365+
#### Q12
346366
### How can we solve the problem of comparision of 0.1 + 0.2 with 0.3 where `===` operator fails
347367
348368
- The addition of 0.1 and 0.2 will result in to 0.30000000000000004 and the comparision with 0.3 fails
@@ -357,7 +377,7 @@ Usage of `Math.round` depends on the logic used to accomplish the requirement
357377
358378
<br />
359379
360-
#### Q12
380+
#### Q13
361381
### Write a code to iterate over a string
362382
363383
- String can be traversed using its string index or value as string can act like an iterable
@@ -389,7 +409,7 @@ for(let value of str){
389409
390410
<br />
391411
392-
#### Q13
412+
#### Q14
393413
### Write a program to reverse a string
394414
395415
- String can be reversed by iterating it and storing it in reverse order
@@ -419,7 +439,7 @@ The string can be tested if it is __palindrome__, by comparing the actual string
419439
<br />
420440
421441
422-
#### Q14
442+
#### Q15
423443
### Write a program to reverse a string by words. Also show the reverse of each words in place
424444
425445
- The string can be reversed by words, by splitting the string with spaces and joining them back after reverse
@@ -437,7 +457,7 @@ str.split(" ").map(val => val.split("").reverse().join("")).join(" ");
437457
438458
<br />
439459
440-
#### Q15
460+
#### Q16
441461
### Write a program to reverse a given integer number
442462
443463
- The remainder of the number can be fetched and the number can be divided by 10 to remvoe the the digit in loop till number becomes 0
@@ -464,7 +484,7 @@ let numStr = String(num);
464484
465485
<br />
466486
467-
#### Q16
487+
#### Q17
468488
### Write a code to replace all the spaces of the string with underscores
469489
470490
- The string can be split using the space character and can be joined back with underscore to replace all the spaces with strings
@@ -487,7 +507,7 @@ str.replaceAll(" ", "_");
487507
488508
<br />
489509
490-
#### Q17
510+
#### Q18
491511
### Write a function which can convert the time input given in 12 hours format to 24 hours format
492512
```js
493513
// Example
@@ -527,7 +547,7 @@ Conversion of string to lowerCase helps in case insensitive comparision
527547
528548
<br />
529549
530-
#### Q18
550+
#### Q19
531551
### Write a function which accepts a string argument and returns the count of characters between the first and last character 'X'
532552
```js
533553
// Example
@@ -554,7 +574,7 @@ function getTheGapX(str) {
554574
555575
<br />
556576
557-
#### Q19
577+
#### Q20
558578
### Write a function to truncate a string to a certain number of letters
559579
```js
560580
// Example
@@ -578,7 +598,7 @@ function truncateString(str, charCount) {
578598
579599
<br />
580600
581-
#### Q20
601+
#### Q21
582602
### Write a code to truncate a string to a certain number of words
583603
584604
- The string can be broken in to words array and then `slice` method of array can be used to get the number of words which will then be joined back
@@ -592,7 +612,7 @@ str.split(' ').slice(0, wordLimit).join(' '); // "JavaScript is si
592612
593613
<br />
594614
595-
#### Q21
615+
#### Q22
596616
### Show the creation of Regular Expression in JavaScript
597617
598618
- Regular expressions are patterns used to match character combinations in strings
@@ -618,7 +638,7 @@ In JavaScript, regular expressions are objects
618638
619639
<br />
620640
621-
#### Q22
641+
#### Q23
622642
### Create a regular expression to validate if the given input is valid Indian mobile number or not
623643
```js
624644
// Example
@@ -651,7 +671,29 @@ String has method `match` which returns array of matches or null
651671
652672
<br />
653673
654-
#### Q23
674+
#### Q24
675+
### Write a function which returns a list of elements which contains at least one character as digit
676+
```js
677+
// Example
678+
numInStr(['1a', 'a', '2b', 'b'])); // ['1a', '2b']
679+
numInStr(['abc', 'abc10'])); // ['abc10']
680+
numInStr(['abc', 'ab10c', 'a10bc', 'bcd'])); // ['ab10c', 'a10bc']
681+
numInStr(['this is a test', 'test1'])); // ['test1']
682+
```
683+
684+
- A test for digit after looping through the array would give the list of values having at least one digit string
685+
686+
```js
687+
function numInStr(mixArray){
688+
return mixArray.filter((value) => {
689+
return /[0-9]/.test(value);
690+
});
691+
}
692+
```
693+
694+
<br />
695+
696+
#### Q25
655697
### Write a function which checks if a given search text is present either in the beginning of the first name or the second name
656698
```js
657699
// Example
@@ -676,7 +718,7 @@ Case insensitive match is happening for the search text in the string represente
676718
677719
<br />
678720
679-
#### Q24
721+
#### Q26
680722
### Write a function to chop a string into chunks of a given length and return it as array
681723
```js
682724
// Example
@@ -711,7 +753,7 @@ function stringChop(str, size = str.length) {
711753
712754
<br />
713755
714-
#### Q25
756+
#### Q27
715757
### Write a code to remove all the vowels from a given string
716758
717759
- `replace` method on String accepts a string or regex as the argument
@@ -726,7 +768,7 @@ str.replace(/[aeiou]/gi, ''); // _lv_JvScrpt
726768
727769
<br />
728770
729-
#### Q26
771+
#### Q28
730772
### Create a function which returns random hex color code
731773
732774
- The color code is popularly represented in hexadecimal format for RGB colors
@@ -749,7 +791,7 @@ function getGetHEXColorCode() {
749791
750792
<br />
751793
752-
#### Q27
794+
#### Q29
753795
### Write a function which accepts two valid dates and returns the difference between them as number of days
754796
755797
- The difference between 2 dates in JavaScript will give the time difference in milliseconds
@@ -774,7 +816,7 @@ getDaysBetweenDates('10/15/2020', '12/1/2020'); // 47
774816
775817
<br />
776818
777-
#### Q28
819+
#### Q30
778820
### Show the usage of template literals with expression interpolation and tagged templates
779821
780822
- Template literals are string literals allowing embedded expressions and support multi lines
@@ -810,7 +852,7 @@ myTag`Note: ${person} is a member of following communities: ${membership}`;
810852
811853
<br />
812854
813-
#### Q29
855+
#### Q31
814856
### Write a code to show the working of `try...catch...finally`
815857
816858
- The `try` statement consists of a try-block, which contains one or more statements. At least one catch-block, or a finally-block, must be present
@@ -837,7 +879,7 @@ try {
837879
838880
<br />
839881
840-
#### Q30
882+
#### Q32
841883
### Show the creation and usage of `symbol` with code
842884
843885
- A "symbol" represents a unique identifier

0 commit comments

Comments
 (0)