algorithm problems Flashcards
We’ll pass you an array of two numbers. Return the sum of those two numbers plus the sum of all the numbers between them. The lowest number will not always come first.
For example, sumAll([4,1]) should return 10 because sum of all the numbers between 1 and 4 (both inclusive) is 10.
Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays.
Note: You can return the array with its elements in any order.
You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
Note: You have to use the arguments object.
Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching name and value pairs (second argument). Each name and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array.
For example, if the first argument is [{ first: “Romeo”, last: “Montague” }, { first: “Mercutio”, last: null }, { first: “Tybalt”, last: “Capulet” }], and the second argument is { last: “Capulet” }, then you must return the third object from the array (the first argument), because it contains the name and its value, that was passed on as the second argument.
Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
Pig Latin is a way of altering English Words. The rules are as follows:
- If a word begins with a consonant, take the first consonant or consonant cluster, move it to the end of the word, and add ay to it.
- If a word begins with a vowel, just add way at the end.
Create a JS function that takes a string and turns it into Pig Latin.
What does the .substring() method do in JavaScript?
This method extracts characters, between two indices (positions), from a string, and returns the string formed between those two indices.
It extracts characters from start to end (the end indice excluded).
It does not change the original string.
If start is greater than end, arguments are swapped: (4, 1) = (1, 4).
Start or end values less than 0, are treated as 0.
Using JavaScript, perform a search and replace on the sentence using the arguments provided and return the new sentence.
First argument is the sentence to perform the search and replace on.
Second argument is the word that you will be replacing (before).
Third argument is what you will be replacing the second argument with (after).
Note: Preserve the case of the first character in the original word when you are replacing it. For example if you mean to replace the word Book with the word dog, it should be replaced as Dog
Pairs of DNA strands consist of nucleobase pairs. Base pairs are represented by the characters AT and CG, which form building blocks of the DNA double helix.
The DNA strand is missing the pairing element. Write a function to match the missing base pairs for the provided DNA strand. For each character in the provided string, find the base pair character. Return the results as a 2d array.
For example, for the input GCG, return [[“G”, “C”], [“C”,”G”], [“G”, “C”]]
The character and its pair are paired up in an array, and all the arrays are grouped into one encapsulating array.
In JavaScript, what is the .charCodeAt() method?
The charCodeAt() method returns the Unicode of the character at a specified index (position) in a string.
Find the missing letter in the passed letter range and return it.
If all letters are present in the range, return undefined.
In JavaScript, what does the .fromCharCode() method do?
This method converts Unicode values to characters.
It is a static method of the String object.
The syntax is always String.(name of this method)
You cannot use myString.(name of this method)
In JavaScript, what is the .new Set() method?
What is a Set?
A method that creates a new X.
A JavaScript X is a collection of unique values.
Each value can only occur once in a X.
A X can hold any value of any data type.
In JavaScript, what is the .flat() method?
The X method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
Write a function that takes two or more arrays and returns a new array of unique values in the order of the original provided arrays.
In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array.
The unique numbers should be sorted by their original order, but the final array should not be sorted in numerical order.