custom map function in javascript
function addtwo(num) {
return num + 2;
}
function timestwo(num) {
return num * 2;
}
function arrplustwo(lst) {
return lst.map(addtwo);
}
function mapper(lst, func) {
for(var num in lst) lst[num] = func(lst[num]);
return lst;
}
/*
var t = [1, 2, 3, 4];
mapper(t, timestwo)
=> [ 2, 4, 6, 8 ]*/