+ 180
[ASSIGNMENT] Arrange the Strings!
Challenge: Arrange the strings! by: Persona Description: Your task is to sort a given string. Each word in the String will contain a single number. This number is the position the word should have in the result. Note: Numbers can be from 1 to 9. So 1 will be the first word (not 0). If the input String is empty, return an empty String. The words in the input String will only contain valid consecutive numbers. For an input: "is2 Thi1s T4est 3a" the function should return "Thi1s is2 3a T4est"
223 Answers
+ 118
Challenge accepted
Like this???
Edit: Thank you for the upvotes and also for the comments, thanks for pointing out the weaknesses of my code for me to correct and also for praising the nice work😉😁 that was done . I could say that it all improved me 👊👊👍👍.
https://code.sololearn.com/cerJ9QGv1lCA/?ref=app
+ 76
Here's, 1-liner:
https://code.sololearn.com/c2riHVJT2Ik3/?ref=app
+ 36
https://code.sololearn.com/cT2zJr3S4S7o/?ref=app
+ 25
Here is my try in Ruby...
https://code.sololearn.com/cLbDzsVRj14Q/#rb
+ 25
My try...work in progress
https://code.sololearn.com/cqxFAhkXb2X8/?ref=app
+ 25
Here's mine finished. I'm still learning Java, so it's not as short as some of these:
https://code.sololearn.com/c3C6TWBBXo3W/#java
+ 24
https://code.sololearn.com/cBsbnuKMVKt2/?ref=app
+ 21
Here's my C# implementation! ✌
LINQ One-Liner〰
words.Select(w => new
{
Word = w,
Order = Regex.Match(w, @"(\d)").Value
})
.OrderBy(p => p.Order)
.Select(p => p.Word)
It has been a really long time I didn't submit LINQ solution and I hope you all enjoy it! Happy Christmas Eve to everyone~ 😄
https://code.sololearn.com/cud7sJqhMlNR/?ref=app
+ 20
https://code.sololearn.com/cYS0CiaJnAZe/?ref=app
+ 18
Here's my approach to my challenge: https://code.sololearn.com/c81U2IH4Xrz9/?ref=app
+ 17
Hmm..
Something different than usual string challenges
+ 17
Just learned Regular Expressions, so I wanted to try to use them in this challenge.
Here is my answer (Python) :
https://code.sololearn.com/csYzu4GioQZd
import re
a = input().split()
for i in range(len(a)):
print(*[elem for elem in a if re.search(str(i+1), elem)], end=' ')
+ 17
This is solution via JavaScript😊
https://code.sololearn.com/WTA1hrwaJYfV/?ref=app
+ 16
my one here
https://code.sololearn.com/cqyV9HHRFQc3/?ref=app
+ 16
// JS Code
var words = prompt("Enter some words", "is2 Thi1s T4est 3a").split(" ");
var updated = [];
//console.log(words)
for(var i = 0; i < words.length; i++){
for(var j = 0; j < words[i].length; j++){
if(words[i][j] <= '9' && words[i][j] >= '0'){
updated[words[i][j]] = words[i];
}
}
}
reswords = updated.join(" ");
console.log(reswords);
// Challenge #1
+ 16
First C++ submission, using C++11.
Does exactly what it should.
https://code.sololearn.com/cMctkpPtTgJd/?ref=app
+ 15
small, simple & readable 😉
Edit: Ruby code added (24/12/2017)
https://code.sololearn.com/c2OT65dQ9WlJ/?ref=app
https://code.sololearn.com/cNf55Ae3sHGS/?ref=app
+ 14
Will do it as soon as I'm on PC