Size: a a a

JavaScript.Ninja

2021 February 21

OK

Oleh Kutsenko in JavaScript.Ninja
Alexey
Олег, привет! я готовлюсь)
Привет, учиться всегда хорошо)
источник

OK

Oleh Kutsenko in JavaScript.Ninja
Roman
у меня есть 1 строка и  там 3 предложения. Нужно в каждом предложении поменять первое и последнее слово, как сделать?
Как советовали можно сделать сплит по точке получив массив предложений и дальше каждое предложение расплитить по пробелы получив слова и переставить местами
Но как мы знаем не все предложения заканчиваются только точками и не все слова можно по пробелы разделить
Тут нужно понимать для чего задача
источник

R

Roman in JavaScript.Ninja
а как сконвертировать код написаный на джаваскрипте в джаву?
источник

VK

Vladimir Klimov in JavaScript.Ninja
Roman
а как сконвертировать код написаный на джаваскрипте в джаву?
Лучше даже не пытаться
источник

R

Roman in JavaScript.Ninja
кто-то может перевести это на джаву?



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})
источник

В

Влад in JavaScript.Ninja
Roman
кто-то может перевести это на джаву?



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})
class SwapFirstLastCharacters {
 static String count(String str)
 {
   // Create an equivalent char array
   // of given string
   char[] ch = str.toCharArray();
   for (int i = 0; i < ch.length; i++) {

     // k stores index of first character
     // and i is going to store index of last
     // character.
     int k = i;
     while (i < ch.length && ch[i] != ' ')
       i++;
     
     // Swapping
     char temp = ch[k];
     ch[k] = ch[i - 1];
     ch[i - 1] = temp;

     // We assume that there is only one space
     // between two words.
   }
   return new String(ch);
 }
 public static void main(String[] args)
 {
   String str = "geeks for geeks";
   System.out.println(count(str));
 }
}
источник

R

Roman in JavaScript.Ninja
Влад
class SwapFirstLastCharacters {
 static String count(String str)
 {
   // Create an equivalent char array
   // of given string
   char[] ch = str.toCharArray();
   for (int i = 0; i < ch.length; i++) {

     // k stores index of first character
     // and i is going to store index of last
     // character.
     int k = i;
     while (i < ch.length && ch[i] != ' ')
       i++;
     
     // Swapping
     char temp = ch[k];
     ch[k] = ch[i - 1];
     ch[i - 1] = temp;

     // We assume that there is only one space
     // between two words.
   }
   return new String(ch);
 }
 public static void main(String[] args)
 {
   String str = "geeks for geeks";
   System.out.println(count(str));
 }
}
это не то
источник

II

Ilya Izilanov in JavaScript.Ninja
Roman
кто-то может перевести это на джаву?



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

Roman in JavaScript.Ninja
Ilya Izilanov
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);
   }
}
Спасибо
источник

Р

Руслан in JavaScript.Ninja
Когда программисту старой закалки предлагают использовать новые технологии
источник

PD

Petya Danchuk in JavaScript.Ninja
Здравствуйте! Джунам задают вопросы на знание Git?
источник

e

ezhidze in JavaScript.Ninja
да
источник

S

Susa in JavaScript.Ninja
Petya Danchuk
Здравствуйте! Джунам задают вопросы на знание Git?
На собеседование будет вопросы от "стейк или бургер" до "напишите код нашей вселенной"
источник

VC

Valera CSS_Junior in JavaScript.Ninja
замыкания в джаваскрипт это только когда мы возвращаем функцию из функции?
источник

S

Susa in JavaScript.Ninja
Valera CSS_Junior
замыкания в джаваскрипт это только когда мы возвращаем функцию из функции?
Почти, когда функция возвращает функцию, но возвращаемая функция обращаться к родительскому скопу и делает какую-то операцию(пример уличивает переменную count у родителя на 1, здесь происходит замыкание )
источник

VC

Valera CSS_Junior in JavaScript.Ninja
Susa
Почти, когда функция возвращает функцию, но возвращаемая функция обращаться к родительскому скопу и делает какую-то операцию(пример уличивает переменную count у родителя на 1, здесь происходит замыкание )
понятно
источник

NK

ID:0 in JavaScript.Ninja
Внимание участников курса JavaScript-инженер. Письма для вас ушли - ищите в почте (надеюсь не в спаме) письмо от illya@javascript.ninja
Завтра начинаем!
источник

G

Gold in JavaScript.Ninja
Valera CSS_Junior
замыкания в джаваскрипт это только когда мы возвращаем функцию из функции?
Нет, вообще функция определенная в глобальной области видимости и имеющая доступ к переменным уже является замыканием
источник

MV

Maxon Vislogurov in JavaScript.Ninja
ID:0
Внимание участников курса JavaScript-инженер. Письма для вас ушли - ищите в почте (надеюсь не в спаме) письмо от illya@javascript.ninja
Завтра начинаем!
источник

MV

Maxon Vislogurov in JavaScript.Ninja
ID:0
Внимание участников курса JavaScript-инженер. Письма для вас ушли - ищите в почте (надеюсь не в спаме) письмо от illya@javascript.ninja
Завтра начинаем!
А есть гайд по оплате?)
источник