-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
random array #92
Comments
https://github.com/yygmind/blog/issues/5
https://github.com/haizlin/fe-interview/issues
https://github.com/qiu-deqing/FE-interview
https://github.com/Advanced-Frontend/Daily-Interview-Question
|
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2019-11-14
*
* @description js 生成 2-32 之间的随机数
* @augments
* @example
* @link https://github.com/haizlin/fe-interview#%E8%B5%B7%E6%BA%90
*
*/
let log = console.log;
const recursiveFun = (arr = [], len = 5, min = 2, max = 32) => {
const rand = Math.floor(Math.random() * (max - min) + min);
if(arr.length < len && !arr.includes(rand)){
arr.push(rand);
return recursiveFun(arr);
} else {
return arr;
}
}
const arr = recursiveFun();
log(`random array`, arr);
|
{
"JavaScript ES6 React Template": {
"prefix": "js6r",
"body": [
"\"use strict\";",
"",
"/**",
" * ",
" * @author xgqfrms",
" * @license MIT",
" * @copyright xgqfrms",
" * @created 2019-11-1$",
" * ",
" * @description $2",
" * @augments $3",
" * @example $4",
" * @link $5",
" * ",
" */",
"",
"let log = console.log;",
"",
"const $2Generator = ($5datas = [], debug = false) => {",
" let result = ``;",
" // do something...",
" return $7result;",
"};",
"",
"",
"",
"export default $2;",
"",
"export {",
" $2,",
"};",
"",
],
"description": "JavaScript ES6 React Template & code snippets!"
}
}
|
js env check"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2019-11-14
*
* @description 写个方法判断当前脚本运行在浏览器还是node环境中 js
* @augments
* @example
* @link https://github.com/haizlin/fe-interview/issues/1514#issuecomment-553188594
*
*/
let log = console.log;
log(`js env`, typeof window === 'undefined' ? 'Node' : 'Browser');
log(`Node global`, global);
log(`Browser window`, window);
// ReferenceError: window is not defined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/haizlin/fe-interview#%E8%B5%B7%E6%BA%90
The text was updated successfully, but these errors were encountered: