前言 上午处理个需求需要从一个总数组中随机取出不同的元素.共使用两个方法.第一种方法较常规,经测试有bug,数据量大以后随机几次返回的对象直接是function而不是object. 当然简单数据类型应该没有这个问题.第二种是使用洗牌算法,亲测有效. 一.常规算法 /** 从数组中随机抽取数据 2016-09-09 **/ function getArrItem(arr, num) { var temp_array = new Array(); for (var index in arr) { t
python3.5 for循环每次取出一个字符(不是字节) #!/usr/bin/env python # -*- coding:utf-8 -*- my_str = "我是哈哈" for i in my_str: my_bytes = bytes(i, 'utf-8') print(my_bytes) my_bytes = bytes(i, 'gbk') print(my_bytes) for i in my_str: my_bytes = bytes(i, 'utf-8') for
示例 Product 表结构: 示例 Product 表数据: 想要的效果是,以 GroupName 字段分组,取出分组中通过 Sort 降序最新的数据,通过示例数据,可以推算出结果数据的 ID 应该为:7.5.3. 示例 SQL 代码: select * from Product p where ID=(select top 1 ID from Product where p.GroupName=GroupName order by Sort desc) order by Sort desc
SQL取出 所有周六 周日的日期 create table SatSun([id] int identity(1,1),[date] datetime,[weekday] char(6)) go declare @datetime datetime,@weekday char(6) set @datetime='2007-1-1' while @datetime<='2007-12-31' begin select @weekday=datename(weekday,@datetime) if
JS如何从一个数组中随机取出一个元素或者几个元素. 假如数组为 var items = ['1','2','4','5','6','7','8','9','10']; 1.从数组items中随机取出一个元素 //code from http://caibaojian.com/js-get-random-elements-from-array.html var item = items[Math.floor(Math.random()*items.length)]; 2.从前面的一篇随机数组中随机