给定一个列表或分隔字符串,输出一个列表或分隔字符串,每个单词的第一个字符在一个字后输出。
对于这个问题,"word“只包含所有可打印的ASCII字符,除了空格、换行符和制表符。
例如,以“下午好,世界!”(空格分隔):
1. String
"Good afternoon, World!"
2. Get the first characters:
"[G]ood [a]fternoon, [W]orld!"
3. Move the characters over. The character at the end gets moved to the beginning.
"[W]ood [G]fternoon, [a]orld!"
4. Final string
"Wood Gfternoon, aorld!"这是密码-高尔夫,所以最短的代码赢了!
Input -> output (space-delimited)
"Good afternoon, World!" -> "Wood Gfternoon, aorld!"
"This is a long sentence." -> "shis Ts i aong lentence."
"Programming Puzzles and Code Golf" -> Grogramming Puzzles Pnd aode Colf"
"Input -> output" -> "onput I> -utput"
"The quick brown fox jumped over the lazy dog." -> "dhe Tuick qrown box fumped jver ohe tazy log."
"good green grass grows." -> "good green grass grows."发布于 2017-05-24 19:21:08
发布于 2017-05-24 22:05:58
s=>s.map((k,i)=>s.slice(i-1)[0][0]+k.slice(1))利用slice(-1)返回数组的最后一个元素这一事实。
f =
s=>s.map((k,i)=>s.slice(i-1)[0][0]+k.slice(1))
console.log(f(['Good', 'afternoon,', 'World!']));
console.log(f(['This', 'is', 'a', 'long', 'sentence.']));
console.log(f(['Programming', 'Puzzles', 'and', 'Code', 'Golf']));
console.log(f(['Input', '->', 'output']));
console.log(f(['The', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'lazy', 'dog.']));
console.log(f(['good', 'green', 'grass', 'grows.']));https://codegolf.stackexchange.com/questions/122450
复制相似问题