11. Convert HTML Entities
Convert the characters &, <, >, “ (double quote), and ‘ (apostrophe), in a string to their corresponding HTML entities.
将HTML的特殊字符转义
1 | function convert(str) { |
12. Spinal Tap Case
Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
字符串格式变换,将给定的字符串用”-“连接起来。
1 | function spinalCase(str) { |
13. Sum All Odd Fibonacci Numbers
Return the sum of all odd Fibonacci numbers up to and including the passed number if it is a Fibonacci number.
求和给定参数内的所有奇Fibonacci数的和。Fibonacci数是后一个数字等于前两个数字和的形式的数列。
1 | /* 递归方式 |
14. Sum All Primes
Sum all the prime numbers up to and including the provided number.
求和给定参数内的所有素数。
1 | function isPrime(num){ |
15. Smallest Common Multiple
Find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters.
给定一个参数数组,返回数组序列内所有数字的最小公倍数。如给定[1,5],则需要返回”1,2,3,4,5”的最小公倍数。
1 | function smallestCommon(m,n){ |
16. Finders Keepers
Create a function that looks through an array (first argument) and returns the first element in the array that passes a truth test (second argument).
给定两个参数,第一个参数是一个数组,第二个参数是一个测试函数,算法需要返回满足该测试函数的第一个数组元素。
1 | function find(arr, func) { |
17. Drop it
Drop the elements of an array (first argument), starting from the front, until the predicate (second argument) returns true.
给定两个参数,第一个参数是一个数组,第二个参数是一个测试函数,算法需要以数组形式弹出满足测试函数的数组元素。
1 | function drop(arr, func) { |
18. Steamroller
Flatten a nested array. You must account for varying levels of nesting.
“Steamroller”,压路机,很形象,将一个嵌套多层的数组扁平化,亦即接受多层嵌套的数组,输出无嵌套数组,且输出数组的元素为输入嵌套的数组元素。
1 | function steamroller(arr, flatArr) { |
19. Binary Agents
Return an English translated sentence of the passed binary string.
翻译给定的二进制串,给定一串01串,输出表示的句子。
1 | function trans(str){ |
20. Everything Be True
Check if the predicate (second argument) is truthy on all elements of a collection (first argument).
给定两个参数,第一个参数是一个对象数组,第二个参数是一个字符串,算法需要判断参数1的对象数组是否都有参数2对应的key且对应的value值为true。
1 | function every(collection,pre){ |
21. Arguments Optional
Create a function that sums two arguments together. If only one argument is provided, then return a function that expects one argument and returns the sum.
js可选参数问题,题干要求求和给定的两个参数,如果只给定了一个参数,则返回一个可以再接收一个参数进行求和的函数。
1 | function isNum(val){ |