Freecodecamp's JavaScript basic algorithm challengeHttps://www.freecodecamp.com2016-07-03JavaScript is not very familiar with the knowledge to solve these problems, it is estimated that some algorithms will be very stupid.1. Invert stringsStr.split (""). Reverse (). Join ("");2. Factorial (factorial 0 results need to be 1)function factorialize (num) { var n=1; for (var i=num;i>0;i--) { n*=i;} return N;}I can't think of a way to add temporary
Search and Replace1. Requirements
Performs a find and replace on a sentence with a given argument and returns a new sentence.
The first parameter is the sentence on which to perform the find and replace.
The second argument is the word that will be replaced (the word before it is replaced).
The third parameter is used to replace the second argument (the replaced word).
Preserves the case of the original word when replaced. For example, if you want to replace the word "bo
Title case a sentence (uppercase in the first letter of the word)
Requirements
Make sure that the first letter of each word in the string is capitalized, and the remainder is lowercase.
Connectors like ' the ' and ' of ' are the same.
Ideas
Use. Split ("") to separate sentences into an array of words.
Use the For loop to separate each word in the array with. Split (") into an array of letters, with the first element in the array capitalized, i.e. the
Diff two Arrays (compare two arrays)1. Requirements
Compares two arrays and returns a new array
The elements of the array are two of all unique array elements in a given array. In other words, returns the difference of two arrays.
2. Ideas
Defines a new array variable that joins the two arrays entered with. Concat () to assign to it
Defines a check function that returns all the unique array elements in a given array of two
Filter out the eligible elements of a
---restore content starts---. Pop () removes the element at the end of the array var removedfrommyarray=myarray.pop () Removes the last element of the MyArray array and assigns it to Removedfrommyarray. Shift removes the first element of the array from Var removedfrommyarray=myarray.shift () and assigns the first elements of the MyArray array to a removedfrommyarray. push () Adds an element at the end of the array. Unshift () Add an element example at the beginning of the array: Myarray.push (["
Map the debrisReturns an array whose contents convert the average elevation of the corresponding element in the original array to its corresponding orbital period.The original array contains the formatted object content, like this {name: ‘name‘, avgAlt: avgAlt} .A formula for calculating orbital periods with orbital heightsA: Half-length axis of the track (m),μ = GMThe value to be evaluated should be the nearest integer, and the orbit is based on the earth.The earth radius is 6367.4447 kilomet
Falsy Bouncer (filter array false values)
Requirements
Deletes all false values in the array. (in JavaScript, false values are,,,, false null 0 "" , undefined and NaN .) )
Ideas
Use. Filter () to reject false values in an array
Use Boolea to set callback function to encounter true value return
Code
1 function bouncer (arr) { 2 // Please write your code here 3 function Res (val)
Return largest Numbers in Arrays (Find out the maximum number of multiple arrays)
Requirements
The large array contains 4 decimal groups, each of which finds the maximum value in each decimal group, and then concatenates them together to form a new array.
Ideas
Use the For loop to iterate through the algebraic groups and arr[i] access each element of the array in a way.
In the first layer for loop, define the variable temp as the first element of the subar
Arguments Optional
1. Requirements
Create a function that calculates the sum of two parameters. If there is only one argument, a function is returned, and the function requests a parameter and then returns the result of the sum.
If none of the two parameters is a valid number, the undefined is returned.
2. Ideas
Determine the number of input data
The number of data is 1, the data type is judged,
Type is a number: Assign this data to a, return a fun
Spinal Tap case1. Requirements
Converts a string to a spinal case.
Spinal case is all-lowercase-words-joined-by-dashes in this form, that is, connecting all lowercase words with hyphens.
2. Ideas
Use. Replace () and regular expressions to separate lowercase letters and capitals with a space
Again
3. Replace the space with a '-' and finally lowercase.function spinalCase(str) { var regex = /\s+|_+/g; str = str.replace(/([a-z])([A-Z])/g, ‘$1 $2‘); return str.replace(regex,
Sum All Primes
1. Requirements
Sum of prime numbers less than or equal to a given number.
Only 1 and its own two approximate numbers are called prime numbers. For example, 2 is a prime number, because it can only be divisible by 1 and 2. 1 is not a prime number because it can only be divisible by itself.
2. Ideas
To define the mark variable in a loop starting from 3 to no more than NUM, initially true
Determines whether I is a prime number in a two-layer cycl
Make a person
1. Requirements
Constructs an object using the method given below: Getfirstname (), Getlastname (), Getfullname (), Setfirstname (first), Setlastname (last), and Setfullname (Firstandlast).
All methods that have parameters accept only one string parameter.
All methods interact with the entity object only.
2. Ideas
Based on the relevant links, an object is constructed using the method given in the topic. Constructing objects
3. Codevar Perso
DNA Pairing1. Requirements
The DNA Strand lacks a paired base. Based on each base, the matching base is found, and the result is returned as a second array.
Base pairs (base pair) is a pair of at and CG that matches the missing base for a given letter.
The letters and the letters to which they are paired are inside an array, and then all the arrays are organized and encapsulated into an array.
2. Ideas
Use. Split (") to divide the entered letter string into an alph
Where Art Thou1. Requirements
Write a function that iterates through an array of objects (the first parameter) and returns an array of all objects that contain matching property-value pairs (the second argument).
If the returned array contains property-value pairs for the source object, then each property-value pair of this object must exist in the collection object.
2. Ideas
Remove the property of source with Object.keys (source)
Use Object.keys () to iterate thro
FreecodecampHttps://www.freecodecamp.com2016-07-03A few days ago in GitHub browsing, accidentally saw a call Freecodecamp open-source project, go into the site after the website feel a bit of Earth green, a bit like a personal build not reliable. But it unexpectedly has an additional public welfare project, is to help non-profit free programming, looked at a bit like really a little. So with the idea of a try to start the inside of the free programmin
Freecodecamp Advanced algorithm address stamp here.Freecodecamp Elementary and intermediate algorithm, basic to a thought can be completed, and advanced algorithm a little trouble, so I will own the solution to write clearly, if there are errors or better solution, welcome message.Validate US Telephone NumbersIf the incoming string is a valid US phone number, it is returned true .In short, the rule of the U.S. number is that the country code (must be
Roman numeral Converter1. Requirements
Converts a given number into Roman numerals
All returned Roman numerals should be in uppercase form
2. Ideas
Array of corresponding Roman numerals for single-digit, 10-bit, hundred, thousand, respectively
Use Math.floor () to remove numbers from each bit of the number, and to find the corresponding Roman numerals in the previously defined array.
3. Codefunction convert(num) {var arr1 = [‘‘,‘I‘,‘II‘,‘III‘,‘IV‘,‘V‘,‘VI‘,‘VI
Reverse a string (flip string)
Title Requirements:
Convert a string to an array
Flipping the array order with the reverse method of the array
Convert an array to a string
Ideas:
Use. Split (") to convert a string into an array of single letters
Use. Reverse () to invert the array
Concatenate array elements into strings using. Join (')
The code is as follows:
1 function reversestring (str) { 2 // Please write y
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.