Skip to content

Commit 74de8f6

Browse files
Added 50 Js Challenge
1 parent 50c2c47 commit 74de8f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2158
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Function which returns a random number in the given range
2+
Create a function which returns a random number in the given range of values both inclusive
3+
4+
## Challenges (0/2 done)
5+
- [ ] randomNumberGeneratorInRange(10, 50) should return a number between 10-50 (inclusive)
6+
- [ ] randomNumberGeneratorInRange(100, 200) should return a number between 100-200 (inclusive)
7+
8+
```js
9+
function randomNumberGeneratorInRange(min, max) {
10+
// write your solution here
11+
12+
return
13+
}
14+
15+
console.log(`My random number: ${randomNumberGeneratorInRange(5, 100)}`)
16+
```
17+
18+
- [Resource-1](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
19+
- [Resource-2](https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function randomNumberGeneratorInRange(min, max) {
2+
// write your solution here
3+
4+
return Math.floor(Math.random() * (max - min + 1)) + min
5+
}
6+
7+
console.log(`My random number: ${randomNumberGeneratorInRange(5, 100)}`)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Write a function to remove array element based on object property?
2+
+ How to remove array element based on object property?
3+
4+
## Challenges (0/3 done)
5+
- [ ] removeArrayElement("money") returns the array without the money object
6+
- [ ] removeArrayElement("id") returns the array without the id object
7+
- [ ] removeArrayElement("cStatus") returns the array without the cStatus object
8+
9+
```js
10+
const array = [
11+
{ field: "id", operator: "eq" },
12+
{ field: "cStatus", operator: "eq" },
13+
{ field: "money", operator: "eq" },
14+
];
15+
16+
const filterField = "money"
17+
18+
function removeArrayElement(filterField) {
19+
// write your solution here
20+
21+
return
22+
}
23+
24+
console.log(`filtered array: ${removeArrayElement(filterField)}`)
25+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const array = [
2+
{ field: "id", operator: "eq" },
3+
{ field: "cStatus", operator: "eq" },
4+
{ field: "money", operator: "eq" },
5+
];
6+
7+
const filterField = "money"
8+
9+
function removeArrayElement(filterField) {
10+
// write your solution here
11+
12+
return array.filter(element => element.field !== filterField)
13+
}
14+
15+
console.log(`filtered array: ${removeArrayElement(filterField)}`)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Return the N-th value of the Fibonacci sequence
2+
+ Return the N-th value of the Fibonacci sequence
3+
4+
## Challenges (0/1 done)
5+
- [ ] function fibonacci(n) returns the N-th value of the Fibonacci sequence
6+
7+
```js
8+
function fibonacci(n) {
9+
// write your solution here
10+
11+
return
12+
}
13+
14+
console.log(`fibonacci value at position 5: ${fibonacci(5)}`)
15+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function fibonacci(n) {
2+
// write your solution here
3+
if(n <= 1) {
4+
return n
5+
}
6+
7+
return fibonacci(n-1) + fibonacci(n-2)
8+
}
9+
10+
console.log(`fibonacci value at position 5: ${fibonacci(5)}`)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Given a number from 0 to 999,999,999,999, spell out that number in English.
2+
3+
## Instructions
4+
5+
- Given a number from 0 to 999,999,999,999, spell out that number in English.
6+
7+
### Step 1
8+
- Handle the basic case of 0 through 99.
9+
- If the input to the program is 22, then the output should be 'twenty-two'.
10+
- Your program should complain loudly if given a number outside the blessed range.
11+
- Some good test cases for this program are:\
12+
0\
13+
14\
14+
50\
15+
98\
16+
-1\
17+
100
18+
19+
### Step 2
20+
- Implement breaking a number up into chunks of thousands.
21+
- So 1234567890 should yield a list like 1, 234, 567, and 890, while the far simpler 1000 should yield just 1 and 0.
22+
- The program must also report any values that are out of range.
23+
24+
### Step 3
25+
- Now handle inserting the appropriate scale word between those chunks.
26+
- So 1234567890 should yield '1 billion 234 million 567 thousand 890'
27+
- The program must also report any values that are out of range. It's fine to stop at "trillion".
28+
29+
### Step 4
30+
- Put it all together to get nothing but plain English.
31+
- 12345 should give twelve thousand three hundred forty-five.
32+
- The program must also report any values that are out of range.
33+
34+
## Challenges (0/2 done)
35+
- [ ] 14 becomes "fourteen".
36+
- [ ] 1323 becomes "one thousand three hundred and twenty-three".
37+
38+
```js
39+
const sayNumberInEnglish = (n /* ADD MORE PARAMETERS IF NEEDED */) => {
40+
// Write your solution here
41+
return
42+
}
43+
44+
console.log(`5635 in english is: ${sayNumberInEnglish(5635)}`)
45+
```
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
var NUMBER2TEXT = {
2+
ones: [
3+
"",
4+
"one",
5+
"two",
6+
"three",
7+
"four",
8+
"five",
9+
"six",
10+
"seven",
11+
"eight",
12+
"nine",
13+
"ten",
14+
"eleven",
15+
"twelve",
16+
"thirteen",
17+
"fourteen",
18+
"fifteen",
19+
"sixteen",
20+
"seventeen",
21+
"eighteen",
22+
"nineteen",
23+
],
24+
tens: [
25+
"",
26+
"",
27+
"twenty",
28+
"thirty",
29+
"fourty",
30+
"fifty",
31+
"sixty",
32+
"seventy",
33+
"eighty",
34+
"ninety",
35+
],
36+
sep: [
37+
"",
38+
" thousand ",
39+
" million ",
40+
" billion ",
41+
" trillion ",
42+
" quadrillion ",
43+
" quintillion ",
44+
" sextillion ",
45+
],
46+
};
47+
48+
const { ones, tens, sep } = NUMBER2TEXT;
49+
50+
const sayNumberInEnglish = (number) => {
51+
let arr = [],
52+
str = "",
53+
i = 0;
54+
if (number.length === 0) {
55+
return;
56+
}
57+
58+
number = parseInt(number, 10);
59+
if (isNaN(number)) {
60+
return;
61+
}
62+
63+
while (number) {
64+
arr.push(number % 1000);
65+
number = parseInt(number / 1000, 10);
66+
}
67+
68+
while (arr.length) {
69+
str =
70+
(function (a) {
71+
var x = Math.floor(a / 100),
72+
y = Math.floor(a / 10) % 10,
73+
z = a % 10;
74+
75+
return (
76+
(x > 0 ? ones[x] + " hundred " : "") +
77+
(y >= 2 ? tens[y] + "-" + ones[z] : ones[10 * y + z])
78+
);
79+
})(arr.shift()) +
80+
sep[i++] +
81+
str;
82+
}
83+
84+
return str;
85+
};
86+
87+
console.log(`5635 in english is: ${sayNumberInEnglish(5635)}`);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Convert given seconds to space age on all planets of our solar system
2+
3+
## Instructions
4+
5+
**Given an age in seconds, calculate how old someone would be on:**
6+
7+
- Mercury: orbital period 0.2408467 Earth years
8+
- Venus: orbital period 0.61519726 Earth years
9+
- Earth: orbital period 1.0 Earth years, 365.25 Earth days, or 31557600 seconds
10+
- Mars: orbital period 1.8808158 Earth years
11+
- Jupiter: orbital period 11.862615 Earth years
12+
- Saturn: orbital period 29.447498 Earth years
13+
- Uranus: orbital period 84.016846 Earth years
14+
- Neptune: orbital period 164.79132 Earth years
15+
16+
**Pluto is not a planet**
17+
18+
So if your function was called with 436575687 as the argument i.e spaceAge(436575687) it should return { "Mercury": 57.44, "Venus": 22.49, "Earth": 13.83, "Mars": 7.36, "Jupiter": 1.17, "Saturn": 0.47, "Uranus": 0.16, "Neptune": 0.08 }
19+
20+
**IMPORTANT!!**
21+
22+
- Your spaceAge function should return the (already given) yearsInAllPlanets object after setting age on each planet (each property of the object)
23+
24+
- THE VALUE OF EACH PROPERTY SHOULD BE A NUMBER AND SHOULD HAVE MAXIMUM 2 DIGITS AFTER THE POINT example 4.34
25+
26+
## Challenges (0/2 done)
27+
- [ ] spaceAge(436575687) should return { "Mercury": 57.44, "Venus": 22.49, "Earth": 13.83, "Mars": 7.36, "Jupiter": 1.17, "Saturn": 0.47, "Uranus": 0.16, "Neptune": 0.08 }
28+
- [ ] spaceAge(65965561) should return { 'Mercury': 8.68 'Venus': 3.4 'Earth': 2.09 'Mars': 1.11 'Jupiter': 0.18 'Saturn': 0.07 'Uranus': 0.02 'Neptune': 0.01 }
29+
30+
```js
31+
const spaceAge = (seconds) => {
32+
const yearsInAllPlanets = {
33+
Mercury: 0,
34+
Venus: 0,
35+
Earth: 0,
36+
Mars: 0,
37+
Jupiter: 0,
38+
Saturn: 0,
39+
Uranus: 0,
40+
Neptune: 0,
41+
}
42+
43+
// Your solution starts here
44+
45+
// Your solution ends here
46+
47+
return yearsInAllPlanets
48+
}
49+
50+
console.log(spaceAge(Math.round(Math.random() * 99999999)))
51+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const spaceAge = (seconds) => {
2+
const yearsInAllPlanets = {
3+
Mercury: 0,
4+
Venus: 0,
5+
Earth: 0,
6+
Mars: 0,
7+
Jupiter: 0,
8+
Saturn: 0,
9+
Uranus: 0,
10+
Neptune: 0,
11+
}
12+
13+
// Your solution starts here
14+
15+
yearsInAllPlanets.Mercury = parseFloat((parseFloat(seconds) / (31557600 * 0.2408467)).toFixed(2))
16+
yearsInAllPlanets.Venus = parseFloat((parseFloat(seconds) / (31557600 * 0.61519726)).toFixed(2))
17+
yearsInAllPlanets.Earth = parseFloat((parseFloat(seconds) / (31557600)).toFixed(2))
18+
yearsInAllPlanets.Mars = parseFloat((parseFloat(seconds) / (31557600 * 1.8808158)).toFixed(2))
19+
yearsInAllPlanets.Jupiter = parseFloat((parseFloat(seconds) / (31557600 * 11.862615)).toFixed(2))
20+
yearsInAllPlanets.Saturn = parseFloat((parseFloat(seconds) / (31557600 * 29.447498)).toFixed(2))
21+
yearsInAllPlanets.Uranus = parseFloat((parseFloat(seconds) / (31557600 * 84.016846)).toFixed(2))
22+
yearsInAllPlanets.Neptune = parseFloat((parseFloat(seconds) / (31557600 * 164.79132)).toFixed(2))
23+
24+
// Your solution ends here
25+
26+
return yearsInAllPlanets
27+
}
28+
29+
console.log(spaceAge(Math.round(Math.random() * 99999999)))

0 commit comments

Comments
 (0)