![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法题
Lee_zz
这个作者很懒,什么都没留下…
展开
-
CodeWars —— A Chain adding function
add(1); // 1 add(1)(2); // 3 add(1)(2)(3); // 6 add(1)(2)(3)(4); // 10 add(1)(2)(3)(4)(5); // 15 在我们平时对函数进行 console.log 打印时,会直接将函数的内容打印在控制台上,这是因为隐式地调用了toString方法,将函数转成了字符串输出。 结果 function add(num){ let count = num function sum(num2){ count += num2 r原创 2021-05-13 17:05:41 · 291 阅读 · 0 评论 -
CodeWars —— Break camelCase
Complete the solution so that the function will break up camel casing, using a space between words. Example "camelCasing" => "camel Casing" "identifier" => "identifier" "" => "" 我的 function solution(string) { return string.s原创 2021-05-13 16:00:22 · 378 阅读 · 0 评论 -
JS数组扁平化的5种方法
var arr1 = [1, [2, 3], [[3, 4, 2], 1], 5, [3]]; => [1, 2, 3, 3, 4, 2, 1, 5, 3] var arr2 = [1,['2', 3], [2], '2', 4] => [1, "2", 3, 2, "2", 4] 1.经典:递归 思路:循环数组,判断arr[i]是否是数组,是数组的话再次调用此函数。 function flatten(arr) { var res = []; for(var i =.转载 2021-05-10 13:43:30 · 513 阅读 · 0 评论 -
Array.from() and new Set()
Array.from() Array.from({ length: 5 }, _ => 0) // [0,0,0,0,0] 含义: 计算出length为5,每一项均为0的数组 基本用法 可用作数组递增 function range(ends) { return Array.from({length: ends}, (_, i) => i + 1) } console.log(range(3)); // [1, 2, 3] 可以将Unicode编码拆解成数组 cons原创 2021-05-08 16:19:27 · 218 阅读 · 0 评论 -
Simple Pig Latin
Simple Pig Latin Description: Move the first letter of each word to the end of it, then add “ay” to the end of the word. Leave punctuation marks untouched. Examples pigIt('Pig latin is cool'); // igPay atinlay siay oolcay pigIt('Hello world !'); // ell原创 2021-05-08 13:55:58 · 136 阅读 · 0 评论