R
Size: a a a
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})
И
DM
.split(/\s+/)
D
А
D
к
к
C
к
Д
var str = "abcdefghijklmnopqrstuvwx"
на выходе
["abcd", "efgh", "ijkl", "mnop", "qrst", "uvwx"]
DT
var str = "abcdefghijklmnopqrstuvwx"
на выходе
["abcd", "efgh", "ijkl", "mnop", "qrst", "uvwx"]
DM
var str = "abcdefghijklmnopqrstuvwx"
на выходе
["abcd", "efgh", "ijkl", "mnop", "qrst", "uvwx"]
const split = (s, l=4) => {
const result = []
for (let i=0; i<s.length; i+=l) {
result.push(s.slice(i, i+l))
}
return result
}
Д
на выходе```
["abcde", "fghi", "jklm", "nopq", "rstu", "vwxyz"]
DM