Skip to content

Commit c77a1ef

Browse files
committed
First Commit
0 parents  commit c77a1ef

File tree

3 files changed

+255
-0
lines changed

3 files changed

+255
-0
lines changed

Note.txt

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#1: Print in Console numbers from 1 to 10
2+
#2: Print in Console the odd numbers less than 100
3+
#3: Print in Console the multiplication table with 7
4+
#4: Calculate the sum of numbers from 1 to 10
5+
#5: Calculate 10!
6+
#6: Calculate the sum of odd numbers greater than 10 and less than 30
7+
#7: Calculate the sum of numbers in an array of numbers
8+
#8: Calculate the average of the numbers in an array of numbers
9+
#9: Find the maximum number in an array of numbers
10+
#10: Create a function that receives an array of numbers and returns an array containing only the positive numbers
11+
#11: Print in Console all the multiplication tables with numbers from 1 to 10
12+
#12: Create a function that will convert from Celsius to Fahrenheit
13+
#13: Create a function that will convert from Fahrenheit to Celsius
14+
#14: Print in Console the first 10 Fibonacci numbers without recursion
15+
#15: Create a function that will find the nth Fibonacci number using recursion
16+
#16: Create a function that will return a Boolean specifying if a number is prime
17+
#17: Calculate the sum of digits of a positive integer number
18+
#18: Print in Console the first 100 prime numbers
19+
#19: Create a function that will return in an array the first "nPrimes" prime numbers greater than a particular number "startAt"
20+
#20: Rotate an array to the left 1 position
21+
#21: Rotate an array to the right 1 position
22+
#22: Reverse an array
23+
#23: Reverse a string
24+
#24: Create a function that will merge two arrays and return the result as a new array
25+
#25: Create a function that will receive two arrays of numbers as arguments and return an array composed of all the numbers that are either in the first array or second array but not in both
26+
#26: Create a function that will receive two arrays and will return an array with elements that are in the first array but not in the second
27+
#27: Create a function that will receive an array of numbers as argument and will return a new array with distinct elements
28+
#28: Calculate the sum of first 100 prime numbers
29+
#29: Print in Console the distance between the first 100 prime numbers
30+
#30-a: Create a function that will add two positive numbers of indefinite size. The numbers are received as strings and the result should be also provided as string.
31+
#31a. Create a function that will return the number of words in a text
32+
#32. Create a function that will capitalize the first letter of each word in a text
33+
#33. Calculate the sum of numbers received in a comma delimited string
34+
#34. Create a function that will return an array with words inside a text
35+
#35. Create a function to convert a CSV text to a “bi-dimensional” array
36+
#36. Create a function that converts a string to an array of characters
37+
#37. Create a function that will convert a string in an array containing the ASCII codes of each character
38+
#38. Create a function that will convert an array containing ASCII codes in a string
39+
#39. Implement the Caesar cypher
40+
#40. Implement the bubble sort algorithm for an array of numbers
41+
#41. Create a function to calculate the distance between two points defined by their x, y coordinates
42+
#42. Create a function that will return a Boolean value indicating if two circles defined by center coordinates and radius are intersecting
43+
#43. Create a function that will receive a bi-dimensional array as argument and a number and will extract as a unidimensional array the column specified by the number
44+
#44. Create a function that will convert a string containing a binary number into a number
45+
#45. Create a function to calculate the sum of all the numbers in a jagged array (array contains numbers or other arrays of numbers on an unlimited number of levels)
46+
#46-a. Find the maximum number in a jagged array of numbers or array of numbers
47+
#47. Deep copy a jagged array with numbers or other arrays in a new array
48+
#48. Create a function to return the longest word(s) in a string
49+
#49. Shuffle an array of strings
50+
#50. Create a function that will receive n as argument and return an array of n unique random numbers from 1 to n.
51+
#51. Find the frequency of characters inside a string. Return the result as an array of objects. Each object has 2 fields: character and number of occurrences.
52+
#52. Calculate Fibonacci(500) with high precision (all decimals)
53+
#53. Calculate 70! with high precision (all digits)
54+
55+
56+
#01. Create a function that takes two numbers as arguments and return their sum.
57+
#02. Write a function that takes an integer minutes and converts it to seconds.
58+
#03. Create a function that takes a number as an argument, increments the number by +1 and returns the result.
59+
#04. Write a function that takes the base and height of a triangle and return its area.
60+
#05. Create a function that takes the age in years and returns the age in days.
61+
#06. Create a function that takes an array containing only numbers and return the first element.
62+
#07. Create a funtion that takes vooltage and current and returns the calculated power.
63+
64+
65+
##Array Problem Solving
66+
01. Create a function that takes an array containing only numbers and return the first element.
67+
02. Given two arguments, return an array which contains these two arguments.
68+
03.Given an object containing counts of both upvotes and downvotes, return what vote count should be displayed. This is calculated by subtracting the number of downvotes from upvotes.
69+
04. Write a function to reverse an array.
70+
05. You can assign variables from arrays like this:
71+
const arr = [1, 2, 3, 4, 5, 6]
72+
let a = arr[0]
73+
let b = arr[1]
74+
75+
console.log(a) // outputs 1
76+
console.log(b) // outputs 2
77+
With ES6, you can assign variables from arrays in a much more succinct way. Create variables a and b from the given array using the ES6 destructuring assignment syntax, where a === 1 and b === 2.
78+
79+
06. Create a function that accepts an array and returns the last item in the array.
80+
07. Create a function that takes an array and returns the types of values (data types) in a new array.
81+
08. Create a function that takes an array of integers and strings. Convert integers to strings and return the new array.
82+
09. Create a function to concatenate two integer arrays.
83+
10. Create a function that takes two numbers num1, num2, and an array arr and returns an array containing all the numbers in arr greater than num1 and less than num2.
84+
11. Create a function that finds the index of a given item. If the item is not present, return -1.
85+
12. Rotate the Array by One Given an array, rotate the values clockwise by one (the last value is sent to the first position).
86+
13. Check if an Array Contains a Given Number Write a function to check if an array contains a particular number.
87+
14. Array of Strings to Array of Numbers Create a function that takes as a parameter an array of "stringified" numbers and returns an array of numbers.
88+
15. Multiply Every Array Item by Two Create a function that takes an array with numbers and return an array with the elements multiplied by two.
89+
16. Array of Word Lengths Create a function that takes an array of words and transforms it into an array of each word's length.
90+
17. Find the Smallest and Biggest Numbers Create a function that takes an array of numbers and return both the minimum and maximum numbers, in that order.
91+
18. Number Split Given a number, return an array containing the two halves of the number. If the number is odd, make the rightmost number higher.
92+
19. Filter out Strings from an Array Create a function that takes an array of non-negative integers and strings and return a new array without the strings.
93+
20. Sort by String Length Create a function that returns an array of strings sorted by length in ascending order.
94+
21. Converting Objects to Arrays Write a function that converts an object into an array, where each element represents a key-value pair in the form of an array.
95+
22. Array of Multiples Create a function that takes two numbers as arguments (num, length) and returns an array of multiples of num until the array length reaches length.
96+

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## JavaScript Problem Solbing
2+
3+
**1: Print in Console numbers from 1 to 10**
4+
5+
```
6+
for (let i = 1; i <= 10; i++) {
7+
console.log(i);
8+
}
9+
```
10+
11+
**Run ESLint**
12+
13+
You may want to run it to check code quality.
14+
15+
```
16+
17+
npm run lint
18+
19+
```

script.js

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// #1: Print in Console numbers from 1 to 10
2+
for (let i = 1; i <= 10; i++) {
3+
console.log(i);
4+
}
5+
6+
// #2: Print in Console the odd numbers less than 100
7+
for (let i = 1; i <= 100; i += 2) {
8+
// console.log(i);
9+
}
10+
11+
// #3: Print in Console the multiplication table with 7
12+
for (let i = 1; i <= 10; i++) {
13+
// console.log(`7 x ${i} = ${i * 7}`);
14+
}
15+
16+
// #4: Calculate the sum of numbers from 1 to 10
17+
let sum = 0;
18+
for (let i = 1; i <= 10; i++) {
19+
sum += i;
20+
}
21+
// console.log(sum);
22+
// #5: Calculate 10!
23+
let fabCalculate = 1;
24+
for (let i = 1; i <= 10; i++) {
25+
fabCalculate *= i;
26+
}
27+
// console.log(fabCalculate);
28+
29+
// #6: Calculate the sum of odd numbers greater than 10 and less than 30
30+
let sumOdd = 0;
31+
for (let i = 10; i <= 30; i += 2) {
32+
sumOdd += i;
33+
}
34+
// console.log(sumOdd);
35+
36+
// #7: Calculate the sum of numbers in an array of numbers
37+
let arr = [50, 67, 20, 84, 91, 40, 69];
38+
let arrTotal = 0;
39+
for (let i = 0; i < arr.length; i++) {
40+
arrTotal += arr[i];
41+
}
42+
// console.log(arrTotal);
43+
44+
// #8: Calculate the average of the numbers in an array of numbers
45+
const arrAverage = (arr) => {
46+
let arrTotal = 0;
47+
for (let i = 0; i < arr.length; i++) {
48+
arrTotal += arr[i];
49+
}
50+
return arrTotal / arr.length;
51+
};
52+
// console.log(arrAverage(arr));
53+
54+
// #9: Find the maximum number in an array of numbers
55+
const findMaxNumber = (arr) => Math.max(...arr);
56+
57+
// console.log(findMaxNumber(arr));
58+
59+
// #10: Create a function that receives an array of numbers and returns an array containing only the positive numbers
60+
const getPositiveNumber = (arr) => {
61+
const newArr = [];
62+
for (let i = 0; i < arr.length; i++) {
63+
if (arr[i] % 2 == 0) {
64+
newArr.push(arr[i]);
65+
}
66+
}
67+
return newArr;
68+
};
69+
// console.log(getPositiveNumber(arr));
70+
// #11: Print in Console all the multiplication tables with numbers from 1 to 10
71+
72+
const printMultiplicationTable = (n) => {
73+
for (let i = 1; i <= n; i++) {
74+
for (let j = 1; j <= 10; j++) {
75+
// console.log(`${i} x ${j} = ${i * j}`);
76+
}
77+
}
78+
};
79+
printMultiplicationTable(5);
80+
81+
// #12: Create a function that will convert from Celsius to Fahrenheit
82+
const celsiustoFahrenheit = (n) => n * 1.8 + 32;
83+
// console.log(celsiustoFahrenheit(50));
84+
85+
// #13: Create a function that will convert from Fahrenheit to Celsius
86+
87+
const fahrenheittoCelsius = (n) => ((n - 32) * 5) / 9;
88+
// console.log(fahrenheittoCelsius(50));
89+
90+
// #14: Print in Console the first 10 Fibonacci numbers without recursion
91+
var f0 = 0;
92+
// console.log(f0);
93+
var f1 = 1;
94+
// console.log(f1);
95+
96+
for (var i = 2; i < 10; i++) {
97+
var fi = f1 + f0;
98+
// console.log(fi);
99+
100+
f0 = f1;
101+
f1 = fi;
102+
}
103+
104+
// #15: Create a function that will find the nth Fibonacci number using recursion
105+
106+
function findFibonacci(n) {
107+
if (n == 0) return 0;
108+
109+
if (n == 1) return 1;
110+
111+
return findFibonacci(n - 1) + findFibonacci(n - 2);
112+
}
113+
114+
var n = findFibonacci(20);
115+
// console.log(n);
116+
117+
// #16: Create a function that will return a Boolean specifying if a number is prime
118+
119+
function isPrime(num) {
120+
for (var i = 2; i < num; i++)
121+
if (num % i === 0) {
122+
return num < 1;
123+
}
124+
return num > 1;
125+
}
126+
// console.log(isPrime(6));
127+
128+
// Check Leap Year Using if...else
129+
function checkLeapYear(year) {
130+
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
131+
return year > 1;
132+
} else {
133+
return year < 1;
134+
}
135+
}
136+
console.log(checkLeapYear(2025));
137+
138+
const obj = {
139+
color: "red",
140+
};

0 commit comments

Comments
 (0)