Refactor
Problems and Solutions
Reverse String
Write a function reverseString(str) that takes in a string. The function should return a new string where the order the characters is reversed.
Range
Write a function range(min, max) that takes in two numbers. The function should return an array containing all numbers from min to max inclusive.
Define this function using function expression syntax.
Log Between Stepper Recall
Write a function logBetweenStepper(min, max, step) that takes in 3 numbers as parameters. The function should print out numbers between min and max at step intervals. See the following examples.
Hint: this function only needs to print using console.log it does not need to return.
Reverse Sentence
Write a function reverseSentence(sentence) that takes in a sentence as an arg. The function should return a new sentence where the order of the words is reversed. Note that you should reverse the order among words, not the order among characters.
My Includes
Write a function myIncludes(arr, target) that accepts an array and an target value as args. The function should return a boolean indicating whether the target is found in the array. Solve this without Array#includes or Array#indexOf.
Initials
Write a function initials(name) that accepts a full name as an arg. The function should return the initials for that name.
Sum Array Recall
Write a function sumArray(array) that takes in an array of numbers and returns the total sum of all the numbers.
Factors Of
Write a function factorsOf(num) that takes in a number as an arg. The method should return an array containing all positive numbers that are able to divide into num with no remainder.
Define this function using function expression syntax.
My Index Of
Write a function myIndexOf(arr, target) that takes in an array and target value as args. The function should return the first index where the target is found in the array. If the target is not found, it should return -1. Solve this without using Array#indexOf.
Vowel Counter Recall
Write a function, countVowels(word), that takes in a string word and returns the number of vowels in the word. Vowels are the letters "a", "e", "i", "o", "u".
Has Vowel
Write a function hasVowel(str) that takes in a string. The function should return a boolean, true if the string contains at least one vowel, false otherwise. Vowels are the letters a, e, i, o, u.
Odd Numbers
Write a function oddNumbers(min, max) that takes in two numbers as args. The function should return an array containing all odd numbers between min and max, exclusive.
Define this function using function expression syntax.
Fizz Buzz Array
Write a function fizzBuzz(max) that accepts a number as an arg. The function should return an array containing all positive numbers less than max that are divisible by either 3 or 5, but not both.
First Vowel
Write a function firstVowel(str) that takes in a string and returns the first vowel that appears sequentially in the string.
Even Numbers
Write a function evenNumbers(max) that takes in a number as an arg. The function should return an array containing all positive, even numbers that are less than max.
Define this function using function expression syntax.
Is Prime Recall
Define a function isPrime(number) that returns true if number is prime. Otherwise, false. A number is prime if it is only divisible by 1 and itself.
Last Vowel
Write a function lastVowel(str) that takes in a string and returns the last vowel that appears sequentially in the string. Note that the string may contain capitalization.
Hint: You may find the String#toLowerCase or String#toUpperCase methods useful
Pit Pat
Write a function pitPat(max) that accepts a number as an arg. The function should return an array containing all positive numbers less than or equal to max that are divisible by either 4 or 6, but not both.
Remove Last Vowel
Write a function removeLastVowel(word) that takes in a string and returns the string with its last vowel removed.
Pairs Maker
Write a function pairsMaker(arr) that takes in a an array as an argument. The function should return a 2D array where the subarrays represent unique pairs of element from the input array.
Min Value
Write a function minValue(nums) that takes in an array of numbers as an arg. The function should return the smallest number of the array. If the array is empty, the function should return null.
Two Sum
Write a function twoSum(arr, target) that accepts an array and a target number as args. The function should a return a boolean indicating if two distinct numbers of the array add up to the target value. You can assume that input array contains only unique numbers.
Rotate Right
Write a function rotateRight(array, num) that takes in an array and a number as args. The function should return a new array where the elements of the array are rotated to the right num times. The function should not mutate the original array and instead return a new array.
Define this function using function expression syntax.
HINT: you can use Array#slice to create a copy of an array
Two Dimensional Sum
Write a function twoDimensionalSum(arr) that takes in a 2D array of numbers and returns the total sum of all numbers.
Rotate Left
Write a function rotateLeft(array, num) that takes in an array and a number as args. The function should rotate the elements of the array to the left num times, mutating the original array. The function should return undefined.
Define this function using function expression syntax.
Pig Latin Recall
Pig Latin is a fun take on the English language where you move any consonant cluster from the start of the word to the end of the word; when words begin on a vowel, you simply add "-yay". Vowels are "aeiou".
Write a function pigLatinWord that takes in a word string and translates the word into Pig Latin. For this problem use the String#slice method. The slice() method extracts a section of a string and returns it as a new string, without modifying the original string.
Hint: Remember the String#includes method!
Least Common Multiple
Write a function leastCommonMultiple(num1, num2) that accepts two numbers as arguments. The functions should return the smallest number that is divisible by both num1 and num2.
Normal Solution
GCD Recursive Solution
Last updated