showing results for - "sample in javascript"
Lautaro
02 Aug 2018
1function sample(arr, req) {
2        arr = arr.sort(()=>{ return 0.5 - Math.random() }) ;
3        let i = 0,
4            array = [];
5        while (i < req) {
6            array.push(arr[i])
7                ++i
8        }
9        return array
10    }
11
12//example  
13let arr = [1,2,3 ,4,5] ;
14console.log( sample(arr , 2) )   // will return two  random items 
Nicolò
14 Feb 2016
1var c = 23;
2Console.WriteLine(c);