Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

7
LINES

< > BotCompany Repo | #337 // map

Lua code

1  
function map(list, f)
2  
  local tbl2, n, i = {}, #list, 1
3  
  for i=1, n do
4  
    tbl2[i] = f(list[i])
5  
  end
6  
  return tbl2
7  
end

Author comment

A nice little map function (for lists) for you to copy or include :-)

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #337
Snippet name: map
Eternal ID of this version: #337/1
Text MD5: 0daa29a276ef0bb5f079b88451157c45
Author: stefan
Category:
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-01-30 15:38:50
Source code size: 126 bytes / 7 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 581 / 151
Referenced in: [show references]