"함수 map()"의 두 판 사이의 차이

1번째 줄: 1번째 줄:
;map
;map
==JavaScript==
[[category: JavaScript]]
<source lang='JavaScript'>
var numbers = [1, 4, 9];
var roots = numbers.map(Math.sqrt);
// roots is now [1, 2, 3]
// numbers is still [1, 4, 9]
</source>
<source lang='JavaScript'>
var numbers = [1, 5, 10, 15];
var doubles = numbers.map(function(x) {
  return x * 2;
});
// doubles is now [2, 10, 20, 30]
// numbers is still [1, 5, 10, 15]
</source>


==Python==
==Python==

2017년 6월 5일 (월) 20:50 판

map

1 JavaScript

var numbers = [1, 4, 9];
var roots = numbers.map(Math.sqrt);
// roots is now [1, 2, 3]
// numbers is still [1, 4, 9]
var numbers = [1, 5, 10, 15];
var doubles = numbers.map(function(x) {
   return x * 2;
});
// doubles is now [2, 10, 20, 30]
// numbers is still [1, 5, 10, 15]

2 Python

Python 3
numbers = [1, 2, 3, 4, 5, 6]
print( list(map(lambda x: x * 2 - 1, numbers)) )
# [1, 3, 5, 7, 9, 11]
numbers = [1, 2, 3, 4, 5, 6]
print( [x * 2 - 1 for x in numbers] )
# [1, 3, 5, 7, 9, 11]

3 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}