![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
JS学习手册
豆浆怎么都买不到
这个作者很懒,什么都没留下…
展开
-
[JavaScript] 小练习 Steamroller
function steamrollArray(arr) { let flattenedArray = []; //recursion function function flattenArray(arg){ //initialize an empty array if(!Array.isArray(arg)) flattenedArray.push(a...翻译 2018-08-04 12:03:44 · 129 阅读 · 0 评论 -
[JavaScript] 小练习 binary string transformation
function binaryAgent(str) { return String.fromCharCode(...str.split(" ").map((char) => parseInt(char,2))); } binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010...翻译 2018-08-04 15:18:31 · 307 阅读 · 0 评论 -
[JavaScript] 小练习 check if every object in list has the property
function(collection, pre){ return collection.every( (obj) => obj.hasOwnProperty(pre) && Boolean(obj[pre])) } //test case check if every object in the array has the property or...翻译 2018-08-04 15:41:36 · 98 阅读 · 0 评论 -
[JavaScript] 小练习 Arguments Optional
function addTogether() { var args = Array.from(arguments); return args.some(arg => typeof(arg)!=='number')? undefined: args.length > 1 ? args.reduce((acc,n) => acc+=n, 0):...翻译 2018-08-04 16:16:45 · 201 阅读 · 0 评论 -
[JavaScript] 小练习 US telephone number validator
function telephoneCheck(str) { // regular expression making up var reg = /^(1\s?)?(\(\d{3}\)|\d{3})[\-\s]?\d{3}[\-\s]?\d{4}$/; return reg.test(str); } //test case telephoneCheck("555-555-5555"...翻译 2018-08-05 09:53:21 · 221 阅读 · 0 评论 -
[JavaScript] 小练习 Cash Register 找零钱
原题: Design a cash register drawer function checkCashRegister()that accepts purchase price as the first argument (price), payment as the second argument (cash), and cash-in-drawer (cid) as the thir...原创 2018-08-05 16:42:30 · 955 阅读 · 0 评论 -
[JavaScript] 小练习 阶乘
使用递归来返回阶乘值; 0的阶乘等于1; function factorialize(num) { return num>0? num * factorialize(num-1):1; } // test case; factorialize(5);原创 2018-08-06 16:54:42 · 192 阅读 · 0 评论 -
[JavaScript] 小练习 生成斐波那契数列
function sumFibs(num) { if(num<2) return 1; //initialize an array with the first two numbers; var arr = [1,1]; //generate the array with While loop while((arr[arr.length-1] + arr[arr.len...原创 2018-08-02 17:37:01 · 301 阅读 · 0 评论 -
[JavaScript] 小练习 给出小于 arg 的所有质数的总和
function sumPrimes(num) { // arg smaller than 2 is unnecessary.. if(num<2) return 'invalid input'; // create a full array.. var arr=[]; for (let iterator=2; iterator<=num; iterator++)...原创 2018-08-03 10:40:28 · 175 阅读 · 0 评论