$30
Functions to implement
For your first function, you will calculate each element with the following equation x^2 - 7 and determine if the
Math.abs of the result is prime or not. You will return an object with the result as the key and true/false as the value That means that in lab1.test.js , running lab1.questionOne([5, 3, 10]) would return
{18: false, 2: true, 93: false} . (please note that when you console.log the return value it will have quotes around the keys, that is fine like so: {'18': false, '2': true, '93': false} is the same as: {18: false, 2: true, 93: false}
If an empty array is passed in or if the function is called without any input parameters, just return an empty object. You do not have to worry about dealing with different data types passed in. You can assume only arrays with numbers as elements and empty arrays will be passed in to your function (we get to type checking and error handling in lecture 2)
questionTwo(arr);
This function will return a new array that contains no duplicated values.
Note: '1' and 1 are not considered the same value.
If an empty array is passed in, just return an empty array [] . You do not have to worry about dealing with different data types passed in. You can assume only arrays are passed in. In the arrays, numbers and strings are the only element types that are contained (we get to type checking and error handling in lecture 2).
questionThree(arr)
This function will take in an array of strings and you will be finding the anagrams of each other. You will create an object that contains the sorted word as the key, and the value will be an array of the strings that match those exact
letters. You will return an object whose values are greater than 1 (meaning, there are anagrams that are grouped together). If all values in the object only have a length 1, return an empty object.
Note: If the array contains the same words, ie. ["foo", "foo"], consider foo to one, meaning you have to check the value to see if the array already contains the string.
If an empty array is passed in, just return an empty object. You do not have to worry about dealing with different data types passed in. You can assume only an array of strings or an empty array will be passed in to your function (we get to type checking and error handling in lecture 2).
To test this function, you will log the result of 5 calls to lab1.questionThree(str) with different inputs, like so:
console.log(lab1.questionThree(["cat", "act", "foo", "bar"])); // returns and outputs: { act: ["cat", "act"] }
console.log(lab1.questionThree(["race", "care", "foo", "foo", "foo"]));
// returns and outputs: { acer: ["race", "care"] }
questionFour(num1, num2, num3)
This function will take three number inputs and for each input, you will calculate the factorials for each input, add all the results up and divide it by the average of the 3 original inputs. You can assume that all input parameters will be supplied (none missing) and that they will all be numbers. You will return the Math.floor of the final result.