python版本
def add(x,y,f):
return f(x)+f(y)
def f(s):
return 100
print add(2,3,f)
print '---'*10
l = [1,2,3,4,100,5]
def mapFunction(x):
return x*x
r = map(mapFunction,l)
print list(map(str,l))
print '---'*10
def plus(x,y):
return x + y
print reduce(plus,l)
print filter(lambda x: x % 2 == 0, l)
print sorted(l)
print list(map(lambda x: x * x, [1, 2, 3, 4, 5, 6, 7, 8, 9]))
js版本
arr = [1,3,2,4,5];
function pow (x) {
// body...
return x*x;
}
arr.map(pow)
arr.map(Sting)
arr.reduce(function (x,y) {
// body...
return x * y;
});
arr.filter(function (x) {
return x % 2 !== 0;
});
arr.sort();
网友评论