diff --git a/frequently-asked-questions/eight.js b/frequently-asked-questions/eight.js new file mode 100644 index 00000000..5fd1ae3c --- /dev/null +++ b/frequently-asked-questions/eight.js @@ -0,0 +1,6 @@ +//Write a function to check if two strings are anagrams. + +function areAnagrams(str1, str2) { + return str1.split('').sort().join('') === str2.split('').sort().join(''); +} + \ No newline at end of file diff --git a/frequently-asked-questions/five.js b/frequently-asked-questions/five.js new file mode 100644 index 00000000..b1570e4a --- /dev/null +++ b/frequently-asked-questions/five.js @@ -0,0 +1,6 @@ +//Remove Duplicates from an Array + +function removeDuplicates(arr) { + return [...new Set(arr)]; +} + \ No newline at end of file diff --git a/frequently-asked-questions/four.js b/frequently-asked-questions/four.js new file mode 100644 index 00000000..c7872811 --- /dev/null +++ b/frequently-asked-questions/four.js @@ -0,0 +1,6 @@ +//Write a function to find the largest number in an array. + +function findLargest(arr) { + return Math.max(...arr); +} + \ No newline at end of file diff --git a/frequently-asked-questions/nine.js b/frequently-asked-questions/nine.js new file mode 100644 index 00000000..11157a3b --- /dev/null +++ b/frequently-asked-questions/nine.js @@ -0,0 +1,6 @@ +// Write a function to calculate the sum of all elements in an array + +function sumArray(arr) { + return arr.reduce((acc, curr) => acc + curr, 0); +} + \ No newline at end of file diff --git a/frequently-asked-questions/one.js b/frequently-asked-questions/one.js new file mode 100644 index 00000000..c9cec607 --- /dev/null +++ b/frequently-asked-questions/one.js @@ -0,0 +1,6 @@ +//Write a function to reverse a string. + +function findLargest(arr) { + return Math.max(...arr); +} + \ No newline at end of file diff --git a/frequently-asked-questions/seven.js b/frequently-asked-questions/seven.js new file mode 100644 index 00000000..456d4ee0 --- /dev/null +++ b/frequently-asked-questions/seven.js @@ -0,0 +1,6 @@ +//Write a function to count the number of vowels in a string. + +function countVowels(str) { + return (str.match(/[aeiou]/gi) || []).length; +} + \ No newline at end of file diff --git a/frequently-asked-questions/six.js b/frequently-asked-questions/six.js new file mode 100644 index 00000000..92fa2a21 --- /dev/null +++ b/frequently-asked-questions/six.js @@ -0,0 +1,6 @@ +// Write a function to flatten a nested array. + +function removeDuplicates(arr) { + return [...new Set(arr)]; +} + \ No newline at end of file diff --git a/frequently-asked-questions/ten.js b/frequently-asked-questions/ten.js new file mode 100644 index 00000000..cab47ce3 --- /dev/null +++ b/frequently-asked-questions/ten.js @@ -0,0 +1,6 @@ +//Write a function to find the factorial of a number. + +function factorial(n) { + return n <= 1 ? 1 : n * factorial(n - 1); +} + \ No newline at end of file diff --git a/frequently-asked-questions/three.js b/frequently-asked-questions/three.js new file mode 100644 index 00000000..d4fe4207 --- /dev/null +++ b/frequently-asked-questions/three.js @@ -0,0 +1,6 @@ +//Write a function to return the nth Fibonacci number. + +function fibonacci(n) { + return n <= 1 ? n : fibonacci(n - 1) + fibonacci(n - 2); +} + \ No newline at end of file diff --git a/frequently-asked-questions/two.js b/frequently-asked-questions/two.js new file mode 100644 index 00000000..392d5aaf --- /dev/null +++ b/frequently-asked-questions/two.js @@ -0,0 +1,6 @@ +//Write a function to check if a string is a palindrome. + +function isPalindrome(str) { + return str === str.split('').reverse().join(''); +} + \ No newline at end of file