+ 30

CHALLENGE: Split string when character changes

Level : easy Task: 🆎➡️🅰️🅱️ Split a given string when character changes. 🚫 without built functions (as split or regex or pattern...). ✔️Note: the given string can contain all type of characters (alphanumeric, special symbols, spaces) Example: Input: AaaabbbbYY@---..aaaa 555%%%%(((f))) Output: A aaa bbbb YY @ --- .. aaaa 555 %%%% ((( f ))) https://code.sololearn.com/cy0Eh3MfJ3RE

10th Jan 2018, 7:13 PM
LukArToDo
LukArToDo - avatar
22 ответов
+ 7
One-liner in Ruby: puts gets.chomp.chars.chunk(&:itself).flat_map { |x| x[1].join } I am a fan of Simon's response's elegance and speed, though. https://code.sololearn.com/cXUMnSG0WSXi/?ref=app
11th Jan 2018, 9:06 AM
André
André - avatar
11th Jan 2018, 4:30 AM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 15
@Louis Thank you for having noticed it 😉 When checking on Q/A I used the word "split" but not "cut"
11th Jan 2018, 6:35 AM
LukArToDo
LukArToDo - avatar
11th Jan 2018, 7:34 AM
Justine Ogaraku
Justine Ogaraku - avatar
10th Jan 2018, 9:17 PM
Himani
11th Jan 2018, 4:51 AM
Louis
Louis - avatar
+ 11
https://code.sololearn.com/ca9MGjnl5EpA/?ref=app
12th Jan 2018, 9:40 AM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
+ 10
I'm so late to this, oh well, here's my attempt on the challenge ; ) Thanks @LukArToDo, https://code.sololearn.com/ck0pTecQ8NEL/?ref=app
12th Jan 2018, 2:39 PM
Ipang
+ 9
My try.. OOP style.. Enter a line, press↩ and enter a number(optional). For a default case type nothing. https://code.sololearn.com/cnhMnDSB5x85/?ref=app
10th Jan 2018, 11:20 PM
AZTECCO
AZTECCO - avatar
11th Jan 2018, 6:37 AM
Mahdi Cheikhrouhou
Mahdi Cheikhrouhou - avatar
12th Jan 2018, 12:53 AM
Med Arezki
Med Arezki - avatar
12th Jan 2018, 1:58 PM
Kartik
Kartik - avatar
+ 7
my try!! this is the funniest code i have ever made!! great challenge!!! https://code.sololearn.com/cR0oLkUCwnqq/?ref=app
12th Jan 2018, 7:43 PM
Saurabh Tiwari
Saurabh Tiwari - avatar
10th Jan 2018, 7:35 PM
Simon
Simon - avatar
+ 6
https://code.sololearn.com/WogbyhVCm145/?ref=app
12th Jan 2018, 9:02 AM
Luc Hariman Randrianomenjanahary
Luc Hariman Randrianomenjanahary - avatar
+ 5
https://code.sololearn.com/cV3Zkv6GUD0H/?ref=app
12th Jan 2018, 11:36 AM
code learner
code learner - avatar
12th Jan 2018, 8:16 PM
Luis Lopes
Luis Lopes - avatar
+ 5
This is my take on splitting a string. https://code.sololearn.com/cK0VH98iP9w9/?ref=app
14th Jan 2018, 8:05 PM
Jeff Anderson
Jeff Anderson - avatar
+ 5
Split string when character changes in js. https://code.sololearn.com/W2mUpwCpqI5p/?ref=app
1st Mar 2018, 10:05 PM
UnknownYmous