OK
Size: a a a
OK
OK
R
VK
R
function swapFirstAndLast(str) {
// Split the string into an array
const words = str.split(" ");
const len = words.length - 1;
// Save the first word and make it lowercase
const first = words.shift().toLowerCase();
// Save the last word and remove any period
const last = words.pop().replace(".", "");
// Capitalize the "new" first word
words.unshift(last.charAt(0).toUpperCase() + last.slice(1));
// Add a period to the last word
words.push(first + ".");
// Put the words together using " "-space
return words.join(" ");
}
const str = "String of words we will use 1. String of words we will use 2. String of words we will use 3.";
const lines = str.split('.').filter(el => !!el)
const output = []
for (const line of lines) {
const swapped = swapFirstAndLast(line);
output.push(swapped)
}
const joined = output.join(' ')
console.log({joined})
В
function swapFirstAndLast(str) {
// Split the string into an array
const words = str.split(" ");
const len = words.length - 1;
// Save the first word and make it lowercase
const first = words.shift().toLowerCase();
// Save the last word and remove any period
const last = words.pop().replace(".", "");
// Capitalize the "new" first word
words.unshift(last.charAt(0).toUpperCase() + last.slice(1));
// Add a period to the last word
words.push(first + ".");
// Put the words together using " "-space
return words.join(" ");
}
const str = "String of words we will use 1. String of words we will use 2. String of words we will use 3.";
const lines = str.split('.').filter(el => !!el)
const output = []
for (const line of lines) {
const swapped = swapFirstAndLast(line);
output.push(swapped)
}
const joined = output.join(' ')
console.log({joined})
R
II
function swapFirstAndLast(str) {
// Split the string into an array
const words = str.split(" ");
const len = words.length - 1;
// Save the first word and make it lowercase
const first = words.shift().toLowerCase();
// Save the last word and remove any period
const last = words.pop().replace(".", "");
// Capitalize the "new" first word
words.unshift(last.charAt(0).toUpperCase() + last.slice(1));
// Add a period to the last word
words.push(first + ".");
// Put the words together using " "-space
return words.join(" ");
}
const str = "String of words we will use 1. String of words we will use 2. String of words we will use 3.";
const lines = str.split('.').filter(el => !!el)
const output = []
for (const line of lines) {
const swapped = swapFirstAndLast(line);
output.push(swapped)
}
const joined = output.join(' ')
console.log({joined})
import java.util.*;
import java.util.stream.Collectors;
public class Swapper {
public static String swapFirstAndLast(String str) {
Deque<String> words = new ArrayDeque<>(Arrays.asList(str.split(" ")));
String first = words.removeFirst().toLowerCase();
String last = words.removeLast().replace(".", "");
String newFirstWord = last.substring(0, 1).toUpperCase() + last.substring(1);
words.addFirst(newFirstWord);
words.addLast(first + ".");
return String.join(" ", new ArrayList<>(words));
}
public static void main(String[] args) {
String str = "String of words we will use 1. String of words we will use 2. String of words we will use 3.";
List<String> lines = Arrays.stream(str.split("\\.")).filter(el -> !el.equals("")).collect(Collectors.toList());
List<String> output = new ArrayList<>();
for (String line : lines) {
String swapped = swapFirstAndLast(line);
output.add(swapped);
}
String joined = String.join(" ", output);
System.out.println(joined);
}
}
R
import java.util.*;
import java.util.stream.Collectors;
public class Swapper {
public static String swapFirstAndLast(String str) {
Deque<String> words = new ArrayDeque<>(Arrays.asList(str.split(" ")));
String first = words.removeFirst().toLowerCase();
String last = words.removeLast().replace(".", "");
String newFirstWord = last.substring(0, 1).toUpperCase() + last.substring(1);
words.addFirst(newFirstWord);
words.addLast(first + ".");
return String.join(" ", new ArrayList<>(words));
}
public static void main(String[] args) {
String str = "String of words we will use 1. String of words we will use 2. String of words we will use 3.";
List<String> lines = Arrays.stream(str.split("\\.")).filter(el -> !el.equals("")).collect(Collectors.toList());
List<String> output = new ArrayList<>();
for (String line : lines) {
String swapped = swapFirstAndLast(line);
output.add(swapped);
}
String joined = String.join(" ", output);
System.out.println(joined);
}
}
Р
PD
e
S
VC
S
VC
NK
G
MV
MV