function getPalindromes(words) { /* This function takes an array of words and returns an array containing only the palindromes. A palindrome is a word that is spelled the same way backwards. E.g. ['foo', 'racecar', 'pineapple', 'porcupine', 'tacocat'] => ['racecar', 'tacocat'] */ }function replaceLettersWithXs(str) { /* This function will receive a string with a mix of characters. It should return the string with all letters replaced by dashes ('X'). For example 'I love Greg' should return 'X XXXX XXXX', and 'Hard as 1, 2, 3' should return 'XXXX XX 1, 2, 3'. */ }function sumDigitsFromString(str) { /* This function takes a string with a jumble of letters and numbers. It should add together all the numbers that appear in the string and return the total. E.g. 'foo5bar6cat1' => 12 'foo99cat' => 18 Tip: For this one, it might be useful to know that the value `NaN` in JavaScript behaves oddly. For example, if you do `typeof NaN` it tells you it's a `"number"`. Odd, eh? */ } function getFactorials(nums) { /* This function takes an array of positive integers and returns an array of the factorials of these numbers. E.g. [4, 3, 2] => [24, 6, 2] The factorial of a number is the product of that number and all the integers below it. E.g. the factorial of 4 is 4 * 3 * 2 * 1 = 24 */ }
Complete these functionsss
function getEvenNumbers(nums) {
/*
This function takes an array of integers and returns an array containing only even integers
*/
result = [];
for(var i=0; i<nums.length; i++){
if(nums[i] %2 == 0)
result.push(nums[i]);
}
return result;
}
function flipBooleans(bools) {
/*
This function takes an array of booleans and should return an array of the opposite booleans.
E.g. [true, true, false] => [false, false, true]
*/
}
function translateKey(student, keyToChange, translation) {
/*
Northcoders is expanding to France ??.
Unfortunately, our team on the ground in Paris doesn't speak the best English and has been providing us with student data partly in French.
This function will take an object representing a student's data, a key that needs changing, and its English translation.
E.g.
const student = {
prénom: 'Carla',
surname: 'Bruni',
job: 'Artist'
}
const keyToChange = 'prénom'
const translation = 'firstName'
It returns a **new object** with the key successfully translated into English.
E.g.
{
firstName: 'Carla',
surname: 'Bruni,
job: 'Artist'
}
*/
}
function findFirstDentist(people) {
/*
This function takes an array of people objects and returns the first found dentist object from the array.
*/
}
function tallyPeopleInManchester(people) {
/* This function receives an array of people objects in for format:
[
{ name: 'Emmeline', lives: { country: 'UK', city: 'Manchester' }, age: 32 }
]
The function should return the number of people who live in the city of Manchester
*/
}
function getPugOwners(dogs) {
/*
This function takes an array of dog objects and returns an array of the names of all the pug owners.
E.g. [
{name: 'Beatrice', breed: 'Lurcher', owner: 'Tom'},
{name: 'Max', breed: 'Pug', owner: 'Izzi'},
{name: 'Poppy', breed: 'Pug', owner: 'Anat'}
]
will return ['Izzi', 'Anat']
*/
}
function pluraliseKeys(obj) {
/*
In this function you will be provided with an object. That object is storing information on keys.
E.g. {
name: 'Tom',
job: ['writing katas', 'marking'],
favouriteShop: [
"Paul's Donkey University",
"Shaq's Taxidermy Shack",
"Sam's Pet Shop"
]
};
In some cases, however, the keys have been very badly named. Good naming convention tells us that the keys containing arrays should be named as plurals.
This function should return a **new object** that is a copy of the input but with any keys that contain arrays pluralised (an 's' added to the end.)
E.g. {
name: 'Tom',
jobs: ['writing katas', 'marking'],
favouriteShops: [
"Paul's Donkey University",
"Shaq's Taxidermy Shack",
"Sam's Pet Shop"
]
}
*/
}
function getWordLengths(str) {
/*
This function takes a string and returns an array of the lengths of each word in the string.
E.g. 'pineapple and black bean curry' => [9, 3, 5, 4, 5]
*/
}
function getPalindromes(words) {
/*
This function takes an array of words and returns an array containing only the palindromes.
A palindrome is a word that is spelled the same way backwards.
E.g. ['foo', 'racecar', 'pineapple', 'porcupine', 'tacocat'] => ['racecar', 'tacocat']
*/
}
function replaceLettersWithXs(str) {
/*
This function will receive a string with a mix of characters. It should return the string with all letters replaced by dashes ('X').
For example 'I love Greg' should return 'X XXXX XXXX', and 'Hard as 1, 2, 3' should return 'XXXX XX 1, 2, 3'.
*/
}
function validMobileNumber(num) {
/*
This function will receive the string of a mobile number. It should return true if the number is a valid UK number and false if not.
A valid mobile number may begin with '07' followed by 9 more digits.
It may also begin with '+447' followed by 9 more digits.
It may also begin with '00447' followed by 9 more digits.
Anything else is invalid.
*/
}
function sumDigitsFromString(str) {
/*
This function takes a string with a jumble of letters and numbers. It should add together all the numbers that appear in the string and return the total.
E.g. 'foo5bar6cat1' => 12
'foo99cat' => 18
Tip: For this one, it might be useful to know that the value `NaN` in JavaScript behaves oddly. For example, if you do `typeof NaN` it tells you it's a `"number"`. Odd, eh?
*/
}
function getWilliams(arr) {
/*
This function takes an array of full names and returns an array containing only the people whose last name is Williams.
E.g. ['Charlotte Jones', 'Rebecca Williams', 'Harry Williams', 'John Williamson', 'William Jones'] => ['Rebecca Williams', 'Harry Williams']
*/
}
function getFactorials(nums) {
/*
This function takes an array of positive integers and returns an array of the factorials of these numbers.
E.g. [4, 3, 2] => [24, 6, 2]
The factorial of a number is the product of that number and all the integers below it.
E.g. the factorial of 4 is 4 * 3 * 2 * 1 = 24
*/
}
function largestNumber(num) {
/*
This function takes a number and returns the largest number that can be made with the same digits.
E.g. if num is 23, the function should return 32.
E.g. if num is 9, the function should return 9.
E.g. if num is 581 the function should return 851.
*/
}
function generateMatrix(n) {
Trending now
This is a popular solution!
Step by step
Solved in 5 steps