Start with an array of integers. Eg: const arr = [1, 2, 3, 2]
Write a function that will loop through the array counting the number of occurences of each value.
The return value of the function will be an Object whose keys will be the numbers from the array and whose values
will be the occurrence count for each value. Eg: { 1:1, 2:2, 3:1 }
Start with an array of integers. Eg: const arr = [17, 8, -92, 12, 56, 44, -33]
Write a function that will loop through the array and find the smallest number in the array. The function will return the smallest number.
For variations of this try searching for the largest number, or find the smallest number that is not negative.
Start with an array filled with any kind of values. Eg: const arr = ['steve', false, null, 0, 1, 2, NaN, 'hello']
Write a function that will loop through the array and find any value that is falsey. The falsey values are false
, 0
, null
, ""
, undefined
and NaN
. Do this without changing the original array. The function returns the new version of the array.
For variations of this try searching for and removing nullish values. Nullish means null or undefined.
Start with an array filled with integers. Eg: const arr = [1, 2, 4, 5, 5, 9, 12]
Write a function that will loop through the array and find the even numbers. Create a new array that holds just the even numbers from the original array. The function should return the new array.
For variations of this try generating an array of the odd numbers, or counting the number of odd and the number of even numbers in the array and return an object with the two counts.
Start with an array filled with numbers. Eg: const arr = [1, 2, 3.14, 6.26, 99.99];
Write a function that calculates and returns the average value from the array.
For a variation try calculating and returning the median value. reference for what a median is
Write a function that accepts a single sentence as an argument and then returns the sentence with the words in reverse order. Eg: I am the one who knocks
would become knocks who one the am I
.
For a variation of this try checking for punctuation at the end of the sentence parameter and keep it at the end of the new sentence, or capitalizing the new first word of the returned sentence. Also change the first letter of the new last word to lowercase (unless the last word is a single letter like "I").
Write a function that will accept a single sentence as an argument and then return a new version of the sentence where the first letter of every word has been capitalized.
Eg: We're going to need a bigger boat
becomes We're Going To Need A Bigger Boat
Write a function that takes a string and a maximum length as parameters. The function should truncate the string to the specified maximum length and add an ellipsis "..."
at the end if it was truncated. For example, if the input string is "Hello, world!"
and the maximum length is 5, the function should return "Hello..."
.
The unicode value for an ellipsis is \u2026
. You can use that in a string.
Write a function that takes a string as a parameter and returns true
if the string is a palindrome (reads the same backward as forward), and false
otherwise. For example, if the input string is "hannah", the function should return true
.