Last active
December 21, 2015 22:38
-
-
Save iambowen/6376281 to your computer and use it in GitHub Desktop.
Node js implementation
XuefengWu
commented
Aug 29, 2013
#!/usr/bin/env node
function printEven(num) {
if((num%2) == 0)
console.log(num/2);
}
var array = [1,2,3,4,5,6,7,8,9,10]
array.forEach(printEven)
Array.range= function(a, b, step){
var A= [];
if(typeof a== 'number'){
A[0]= a;
step= step || 1;
while(a+step<= b){
A[A.length]= a+= step;
}
}
else{
var s= 'abcdefghijklmnopqrstuvwxyz';
if(a=== a.toUpperCase()){
b=b.toUpperCase();
s= s.toUpperCase();
}
s= s.substring(s.indexOf(a), s.indexOf(b)+ 1);
A= s.split('');
}
return A;
}
var numbers = Array.range(1,10);
var result = numbers.filter(function(number){
return number%2 == 0
})
for (var i in result){
console.log(result[i]/2);
}
[1,2,3,4,5,6,7,8,9,10].filter(even_number).map(divide2)
function even_number(element){
return element % 2 == 0
}
function divide2(element){
return element / 2;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment