Skip to content
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

ramda #1

Open
xingdongyu1994 opened this issue Jul 4, 2017 · 0 comments
Open

ramda #1

xingdongyu1994 opened this issue Jul 4, 2017 · 0 comments

Comments

@xingdongyu1994
Copy link
Owner

<title>菜鸟教程(runoob.com)</title> <script src="https://cdn.bootcss.com/ramda/0.24.1/ramda.js"></script> <script>

var isxiao = s => s === "xiao"
var prop = (p, obj) => obj[p];
var propRole = R.curry(prop)("name")
var getresult = R.filter(R.pipe(propRole, isxiao))
var datas=[
{"name":"xiao","age":18},
{"name":"xiao","age":18},
{"namewww":"xi","age":18},
{"name":"mi","age":18}
]

var str = 'Lorem ipsum dolor sit amet consectetur adipiscing elit';
var getsplit = s=> s.split(" ")
var getLength = w=> w.length
var getlengarr = arr => R.map(getLength, arr)
var maxnum = arrs => R.apply(Math.max, arrs)
getresult = R.pipe(
getsplit,
getlengarr,
maxnum
)
var getresult2 = R.pipe(
R.split(' '),
R.map(R.length),
R.reduce(R.max, 0)
)

var data = {
result:"sucess",
name:"xiaomi",
age:5,
tasks:[
{"id":1,"age":18,"username":"job","newdate":"2017-01-01","is":"yes"},
{"id":1,"age":18,"username":"job","newdate":"2017-08-01","is":"no"},
{"id":1,"age":18,"username":"jobs","newdate":"2017-02-01","is":"no"},
{"id":1,"age":18,"username":"jobs","newdate":"2017-09-01","is":"yes"},
{"id":1,"age":18,"username":"jobs","newdate":"2017-03-01","is":"yes"},
{"id":1,"age":18,"username":"jobs","newdate":"2017-01-01","is":"yes"},
{"id":1,"age":18,"username":"jobs","newdate":"2017-11-01","is":"yes"},
{"id":1,"age":18,"username":"job","newdate":"2017-03-01","is":"yes"}
]
}
//提取tasks属性
var onetasks = R.prop("tasks")
//过滤出指定的用户
var filterMember = member => R.filter(
R.propEq('username', member)
);
//在去过滤掉 is都是no的 剩下都是yes的
var rejectarr = nober => R.reject(
R.propEq("is",nober)
)
// 在去按照日期来排序
var sortdate = R.sortBy(R.prop('newdate'))
var lastresult = R.pipe(
onetasks,
filterMember("jobs"),
rejectarr("no"),
sortdate
)
console.log("AAAAAAAAAAAAAAA", data)
console.log("BBBBBBBBBBB", lastresult(data))
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant