最近有个房子合租的广告,有一群恶搞的程序员把联系电话改成一段代码。刚好现在有空,我来让这段代码优雅一点.
- 原始代码:
int[] array = {8,1,5,5,7};
int[] index = {1,0,4,2,4,1,4,0,3,0,4};
String tel = "";
for(int i =0 ; i< index.length; i++){
tel += array[index[i]];
}
System.out.println(tel);
- 伪优雅代码:
int[] array = {8, 1, 5, 5, 7};
int[] index = {1, 0, 4, 2, 4, 1, 4, 0, 3, 0, 4};
Arrays.stream(index)
.map(i -> array[i]).forEach(i -> System.out.print(i));
- Clojure
user=> (map [8, 1, 5, 5, 7] [1, 0, 4, 2, 4, 1, 4, 0, 3, 0, 4])
(1 8 7 5 7 1 7 8 5 8 7)
还有其他语言的来补充!