์ ์๋ ์์:
_.repeat("0",10)
// => ["0","0",... 10 times]
๋๋ ๋ค์๊ณผ ๊ฐ์ด _.range ํจ์๋ฅผ ์์ ํฉ๋๋ค.
_.range(0,0,10), instead of outputting [] outputs the above.
์ฌ์ฉ ์ฌ๋ก๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
var values = ["A","B","C"];
_.object(values)
// => {"A":undefined,"B":undefined,"C":undefined} // wonderful, as expected
๊ทธ๋ฌ๋ ํค/๊ฐ ์์ ๋ชจ๋ ๊ฐ์ ๋์ผํ ๊ฐ์ผ๋ก ์ด๊ธฐํํ๋ ค๋ฉด ์ด๋ป๊ฒ ํด์ผ ํฉ๋๊น?
์ด๊ฒ์ ๋ค๋ฅธ ์ต์
์ผ ์ ์์ง๋ง ์๋ํ์ง ์์ต๋๋ค.
_.object(values,"0") // provide scalar instead of array
// => {"A":undefined,"B":undefined,"C":undefined} // same as before
_repeat๊ฐ ์๋ ๊ฒฝ์ฐ ์๋ํฉ๋๋ค.
_.object(values,_.repeat("0",values.length))
// => {"A":"0","B":"0","C":"0"}
๋ฐฐ์ด ๋ฐ๋ณต ๊ธฐ๋ฅ์ ๊ฒฝ์ฐ +1์
๋๋ค. ์ซ์ ๋ฒ์ ์ ์ฉ์ด๋ฏ๋ก _.range
์์ ํ์ง ์๊ฒ ์ต๋๋ค.
๋ค๋ฅธ ๋ฐฉ๋ฒ ๋์ ์ Lo-Dash๊ฐ ํ๋ ๊ฒ์ฒ๋ผ _.times
๋ฅผ ์์ ํ์ฌ ๊ฐ callback
ํธ์ถ ์ ๊ฒฐ๊ณผ ๋ฅผ
var zeros = _.times(10, function() { return 0; });
// => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
+1 @jdalton.
๋์๊ฒ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ค๋ฅธ ๋ฐฉ๋ฒ ๋์ ์ Lo-Dash๊ฐ ํ๋ ๊ฒ์ฒ๋ผ
_.times
๋ฅผ ์์ ํ์ฌ ๊ฐcallback
ํธ์ถ ์ ๊ฒฐ๊ณผ ๋ฅผ