1. Sum All Numbers in a Range
We’ll pass you an array of two numbers. Return the sum of those two numbers and all numbers between them.
The lowest number will not always come first.
求和给定数组约束范围内的所有数字
1 | function getMaxMin(arr,op){ |
2. Diff Two Arrays
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.
求两个给定数组的diff
1 | function diff(arr1, arr2) { |
3. Roman Numeral Converter
Convert the given number into a roman numeral.
将给定数字转化为罗马数字
1 | function convert(num){ |
4. Where art thou
Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching property and value pairs (second argument). Each property 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.
参数1给定一个若干对象构成的数组,参数2给定一个对象,算法需要从参数1中查找匹配参数2对象的所有对象并以数组形式输出。
1 | function where(collection, source) { |
5. Search and Replace
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).
执行查找和替换,将句子(参数1)中出现的词(参数2)用另一个(参数3)替换
1 | function isFirstUpper(str){ |
6. Pig Latin
Translate the provided string to pig latin.
将给定字符串翻译成”pig latin”形式。pig latin就是一个将单词形变的小游戏:将单词第一个字母移动到最后并添加”ay”结尾,如果单词以元音开头,则添加”way”结尾。
1 | function translate(str) { |
7. DNA Pairing
The DNA strand is missing the pairing element. Take each character, get its pair, and return the results as a 2d array.
DNA配对,DNA的配对形如”AT,CG”模式,亦即出现字母”A”则给之以”T”配对,以此类推。
1 | function pair(str) { |
8. Missing letters
Find the missing letter in the passed letter range and return it.
If all letters are present in the range, return undefined.
查找并返回给定字符序列中缺失的字母,如”bcdef”应返回”a”。
1 | function fearNotLetter(str) { |
9. Boo who
Check if a value is classified as a boolean primitive. Return true or false.
这个不知道为什么会算到中级里来,简直简单的发指。
1 | function boo(bool) { |
10. Sorted Union
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.
接收若干数组参数,返回所有不重复的数组元素并按接收参数的顺序排列。
1 | function unite() { |
中级算法这个系列一共有21道题,为了避免博文篇幅过长,将中级算法系列分成两篇总结,此篇总结1-10题,下一篇总结11-21题。
欢迎留言探讨,共同学习进步。