//升序, 包含from,不包含to
R.range(0,5)
//排序, 根据diff函数
const diff = function(a, b) { return b - a; };
R.sort(diff, [2,5,3,44]]);
//
const mapIndexed = R.addIndex(R.map);
mapIndexed((val, idx) => val + ''+ idx, [1,3,4]);
addIndex
只适用于迭代回调函数是首个参数、列表是最后一个参数的函数。(如果列表参数没有用到,后一个条件可以忽略)。
var mapIndexed = R.addIndex(R.map);
mapIndexed((val, idx) => idx + '-' + val, ['f', 'o', 'o', 'b', 'a', 'r']);
//=> ['0-f', '1-o', '2-o', '3-b', '4-a', '5-r']
合并两个对象的自身属性(不包括 prototype 属性)。如果某个 key 在两个对象中都存在,使用后一个对象对应的属性值。
var a = R.merge(R.__, {x: 0});
a({s:1})
//=> {s:1,x:0}
pick
返回对象的部分拷贝,其中仅包含指定键对应的属性。如果某个键不存在,则忽略该属性。
R.pick(['a', 'd'], {a: 1, b: 2, c: 3, d: 4});
//=> {a: 1, d: 4}
R.pick(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4});
//=> {a: 1}
判断多个字段非空
const reviewsData = {
name: R.prop('name', data),
discription: R.prop('discription', data),
source: R.prop('source', data),
target: R.prop('target', data),
type: R.prop('type', data),
start_date: R.prop('start_date', data),
cycle: R.prop('cycle', data),
start_time: R.prop('start_time', data),
};
const reviewsDataText = {
name: '任务名',
discription: '任务描述',
source: '导入数据源名称',
target:'目标数据源名称',
type: '调度类型',
start_date:'生效时间',
cycle: '调度周期',
start_time: '起始时间'
};
let isEven = n => R.isNil(n) || R.isEmpty(n);
let result = R.filter(isEven, reviewsData); //=> {b: 2, d: 4}
if (result !== undefined) {
let keys = R.keys(result);
if (keys[0] !== undefined) {
let msg = R.prop(keys[0], reviewsDataText);
if (msg !== undefined) {
return message.warn(msg + '不能为空!');
}
}
}
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ ( T | o ) ( Y | o | u | t | h | , | T | o ) ( S | i | m | p | l | e | ! ) \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/