daily pastebin goal
79%
SHARE
TWEET

Untitled

a guest Oct 18th, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 简单实现下 Array.prototype.map 的功能。
  2.  
  3. var arrayMap = function( ary, callback ){
  4.   var i = 0,
  5.   length = ary.length, value,
  6.   ret = [];
  7.  
  8.   for ( ; i < length; i++ ){
  9.     value = callback( i, ary[ i ] );
  10.     ret.push(value );
  11.   }
  12.   return ret;
  13. }
  14.  
  15. var a = arrayMap([ 1, 2, 3 ], function( i, n ){
  16.   return n * 2;
  17. });
  18.  
  19. console.log(a);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top