Skip to content

Commit a467b72

Browse files
committed
two function added
1 parent 4866bb6 commit a467b72

File tree

3 files changed

+80
-51
lines changed

3 files changed

+80
-51
lines changed

Note.txt renamed to Problem.txt

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,45 @@
1313
#13: Create a function that will convert from Fahrenheit to Celsius
1414
#14: Print in Console the first 10 Fibonacci numbers without recursion
1515
#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)
16+
#16: Check Leap Year Using if...else?
17+
#17: Create a function that accepts an array and returns the last item in the array.
18+
#18: Calculate the sum of digits of a positive integer number
19+
#19: Print in Console the first 100 prime numbers
20+
#20: Create a function that will return in an array the first "nPrimes" prime numbers greater than a particular number "startAt"
21+
#21: Rotate an array to the left 1 position
22+
#22: Rotate an array to the right 1 position
23+
#23: Reverse an array
24+
#24: Reverse a string
25+
#25: Create a function that will merge two arrays and return the result as a new array
26+
#26: 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
27+
#27: 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
28+
#28: Create a function that will receive an array of numbers as argument and will return a new array with distinct elements
29+
#29: Calculate the sum of first 100 prime numbers
30+
#30: Print in Console the distance between the first 100 prime numbers
31+
#31-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.
32+
#32. Create a function that will return the number of words in a text
33+
#33. Create a function that will capitalize the first letter of each word in a text
34+
#34. Calculate the sum of numbers received in a comma delimited string
35+
#35. Create a function that will return an array with words inside a text
36+
#36. Create a function to convert a CSV text to a “bi-dimensional” array
37+
#37. Create a function that converts a string to an array of characters
38+
#38. Create a function that will convert a string in an array containing the ASCII codes of each character
39+
#39. Create a function that will convert an array containing ASCII codes in a string
40+
#40. Implement the Caesar cypher
41+
#41. Implement the bubble sort algorithm for an array of numbers
42+
#42. Create a function to calculate the distance between two points defined by their x, y coordinates
43+
#43. Create a function that will return a Boolean value indicating if two circles defined by center coordinates and radius are intersecting
44+
#44. 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
45+
#45. Create a function that will convert a string containing a binary number into a number
46+
#46. 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)
47+
#47-a. Find the maximum number in a jagged array of numbers or array of numbers
48+
#48. Deep copy a jagged array with numbers or other arrays in a new array
49+
#49. Create a function to return the longest word(s) in a string
50+
#50. Shuffle an array of strings
51+
#51. Create a function that will receive n as argument and return an array of n unique random numbers from 1 to n.
52+
#52. 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.
53+
#53. Calculate Fibonacci(500) with high precision (all decimals)
54+
#54. Calculate 70! with high precision (all digits)
5455

5556

5657
#01. Create a function that takes two numbers as arguments and return their sum.

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,29 @@ function checkLeapYear(year) {
198198
console.log(checkLeapYear(2025));
199199
200200
```
201+
202+
**#17: Create a function that accepts an array and returns the last item in the array?**
203+
204+
```
205+
206+
const arr = [50, 90, 80, 66, 85];
207+
const returnLastItem = (arr) => arr[arr.length - 1];
208+
console.log(returnLastItem(arr));
209+
210+
```
211+
212+
**#18: Calculate the sum of digits of a positive integer number?**
213+
214+
```
215+
216+
const sumOfDigits = (n) => {
217+
const newArr = Array.from(String(n), Number);
218+
let sumOfArr = 0;
219+
for (let i = 0; i < newArr.length; i++) {
220+
sumOfArr += newArr[i];
221+
}
222+
return sumOfArr;
223+
};
224+
console.log(sumOfDigits(45465));
225+
226+
```

script.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,18 @@ function checkLeapYear(year) {
119119
}
120120
console.log(checkLeapYear(2025));
121121

122-
// #00: Print in Console the first 10 Fibonacci numbers without recursion
123-
var f0 = 0;
124-
// console.log(f0);
125-
var f1 = 1;
126-
// console.log(f1);
127-
128-
for (var i = 2; i < 10; i++) {
129-
var fi = f1 + f0;
130-
// console.log(fi);
131-
132-
f0 = f1;
133-
f1 = fi;
134-
}
122+
// #17: Create a function that accepts an array and returns the last item in the array?
123+
const arr = [50, 90, 80, 66, 85];
124+
const returnLastItem = (arr) => arr[arr.length - 1];
125+
console.log(returnLastItem(arr));
126+
127+
// #18: Calculate the sum of digits of a positive integer number?
128+
const sumOfDigits = (n) => {
129+
const newArr = Array.from(String(n), Number);
130+
let sumOfArr = 0;
131+
for (let i = 0; i < newArr.length; i++) {
132+
sumOfArr += newArr[i];
133+
}
134+
return sumOfArr;
135+
};
136+
console.log(sumOfDigits(45465));

0 commit comments

Comments
 (0)