当前位置:网站首页>JS written test questions -- random numbers, array de duplication
JS written test questions -- random numbers, array de duplication
2022-07-25 02:49:00 【H5_ ljy】
Please complete it JavaScript Code , Implement a function , Requirements are as follows :
- According to the number range entered [start,end] And random numbers "n" Generate random number
- The generated random number is stored in the array , Return the array
- The returned array cannot have the same elements
const _getUniqueNums = (start,end,n) => {
// The completion code
let arr=[]
for(let i=0;i<n;i++){
let b=Math.ceil(Math.random()*(end-(start)+start))
arr[i]=b;
}
let set1=new Set(arr);
let arr1=Array.from(set1);
return arr1
}
console.log(_getUniqueNums(2,10,4))

Add : There are some knowledge points Math Of random Random , Array de duplication method .
summary : random Random number method , Determine the range format :Math.random()*(end-(start)+start)
Rounding can be used ceil or floor Method .
Array de duplication can be used Set Method , It also uses the non repetition of object key names to achieve, and so on
边栏推荐
- [system design] distributed key value database
- Digital commerce cloud fine chemical industry management platform integrated informatization solution
- Pypi counts the number of Downloads
- Redux best practices "Redux toolkit"
- My creation anniversary (3rd Anniversary)
- Wechat sports field reservation of applet completion works applet graduation design (8) graduation design thesis template
- Arduino IDE for raspberry PI Pico development firmware localization installation tutorial
- [circular array] JS method collection of circular array
- Digital business cloud: how to realize the application value of supplier SRM management system?
- Go multiplexing
猜你喜欢

Ctfshow misc introduction

@Retryable @backoff @recover retry the use of annotations

Conceptual distinction between Po, Bo, VO, dto and POJO

Introduction to web security telent testing and defense

Tp5.1 login configuration method of whether to login public functions (complete login case)

Is it necessary to increase the number of milliseconds and save several KB of memory in the program?
Failed to create data snapshot: lock file [/siyuan/data/assets/image- 2022070216332-jijwccs.png failed: open /siyuan/data/assets/image- 2022070216332-jijwccs.png: permission denied; unable to lock fil

What should I do when the interface encounters jsonstring

【C】 Advanced knowledge of file operation

Project management tool Zen
随机推荐
Flutter apple native Pinyin keyboard input exception on textfield | Pinyin input process callback problem
Clothing ERP | ten advantages of clothing ERP for enterprises
Redis unauthorized access vulnerability recurrence (www.hetianlab.com)
Remote sensing image classification tool and visualization application of WebGIS
【C】 Advanced knowledge of file operation
C: wechat chat software instance (wpf+websocket+webapi+entityframework)
[TinyML]EfficientFormer:Vision Transformers at MobileNet Speed
After six years of precipitation, new consumption has found a digital transformation paradigm
Sequence diagram of UML diagram series
Daily three questions 7.15
Keil compile download error: no algorithm found for: 08000000h - 08001233h solution
Analysis of FLV packaging
Object.defineproperty use
Jenkins configuration plug-in interface displays "suggestions collection" in Chinese
On the economic model of open source ecology
[system design] distributed key value database
[jailhouse article] scheduling policies and system software architectures for mixed criticality
Flume's study notes
Routing policy interferes with routing
Unity refers to a variable in another class (its own instance)