From 7f19ec958e2cbde23c9f893a5b8e36cb6b4c02b5 Mon Sep 17 00:00:00 2001 From: Soubik Date: Wed, 30 Dec 2020 13:02:52 +0530 Subject: [PATCH 01/10] Added Way-Too-Long-Wordsd --- Way Too Long Words/script.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Way Too Long Words/script.js diff --git a/Way Too Long Words/script.js b/Way Too Long Words/script.js new file mode 100644 index 0000000..c4a6f33 --- /dev/null +++ b/Way Too Long Words/script.js @@ -0,0 +1,6 @@ +function wayTooLongWords(word){ + let wFirst = word[0], wLast = word[word.length - 1]; + let len = word.length - 2; + var res = wFirst + len.toString() + wLast; + return res; +} \ No newline at end of file From 46e4e06bbabd4911fd0b339513db01cc038f9fff Mon Sep 17 00:00:00 2001 From: Soubik Bhui <73220513+sb16072007@users.noreply.github.com> Date: Wed, 30 Dec 2020 13:04:00 +0530 Subject: [PATCH 02/10] Create README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c9f600b --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# JavaScript-Algorithms + +## Some Javascript Algorithms From 72f573fe41fa47c1d05a22f9869d32357c89c966 Mon Sep 17 00:00:00 2001 From: Soubik Bhui <73220513+sb16072007@users.noreply.github.com> Date: Wed, 30 Dec 2020 13:14:38 +0530 Subject: [PATCH 03/10] Updated ./Way Too Long Words/script.js --- Way Too Long Words/script.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Way Too Long Words/script.js b/Way Too Long Words/script.js index c4a6f33..90a758b 100644 --- a/Way Too Long Words/script.js +++ b/Way Too Long Words/script.js @@ -1,6 +1,20 @@ -function wayTooLongWords(word){ - let wFirst = word[0], wLast = word[word.length - 1]; - let len = word.length - 2; - var res = wFirst + len.toString() + wLast; - return res; +/* +From CodeForces - + +Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. + +Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. + +This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes. + +Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n". + +You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. +*/ + +function wayTooLongWords(word){ + let wFirst = word[0], wLast = word[word.length - 1]; + let len = word.length - 2; + var res = wFirst + len.toString() + wLast; + return res; } \ No newline at end of file From d06fcadae441d1e80045f66818bc359ba7042bde Mon Sep 17 00:00:00 2001 From: Soubik Bhui <73220513+sb16072007@users.noreply.github.com> Date: Wed, 30 Dec 2020 14:55:49 +0530 Subject: [PATCH 04/10] Add files via upload --- Word/script.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Word/script.js diff --git a/Word/script.js b/Word/script.js new file mode 100644 index 0000000..97cf0d7 --- /dev/null +++ b/Word/script.js @@ -0,0 +1,33 @@ +/* +From CodeForces - + +Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. + +That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, + +vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. + +For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, + +you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. +*/ + +function Word(word) { + var lwrLetter = [], uprLetter = []; + let letter = word.split(''); + let upperCaseLetters = word.toUpperCase().split(''); + for(var i = 0; i < letter.length; i++) { + if(letter[i] === upperCaseLetters[i]) { + uprLetter.push(letter[i]); + } else { + lwrLetter.push(letter[i]); + } + } + if (lwrLetter.length > uprLetter.length) { + return word.toLowerCase(); + } else if (lwrLetter.length < uprLetter.length) { + return word.toUpperCase(); + } else { + return word.toLowerCase(); + } +} \ No newline at end of file From 049df7162865f6a40bdc1f96d829bb19f1c4b4ce Mon Sep 17 00:00:00 2001 From: Soubik Bhui <73220513+sb16072007@users.noreply.github.com> Date: Wed, 30 Dec 2020 14:56:52 +0530 Subject: [PATCH 05/10] Updated ./Word/script.js --- Word/script.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Word/script.js b/Word/script.js index 97cf0d7..9b95feb 100644 --- a/Word/script.js +++ b/Word/script.js @@ -1,5 +1,5 @@ /* -From CodeForces - +From CodeForces - Problem Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. @@ -30,4 +30,4 @@ function Word(word) { } else { return word.toLowerCase(); } -} \ No newline at end of file +} From c832050f45f58dc2a0224279f702864a990bcf19 Mon Sep 17 00:00:00 2001 From: Soubik Bhui <73220513+sb16072007@users.noreply.github.com> Date: Wed, 30 Dec 2020 19:50:22 +0530 Subject: [PATCH 06/10] Added Wrong Subtraction --- Wrong Subtraction/script.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Wrong Subtraction/script.js diff --git a/Wrong Subtraction/script.js b/Wrong Subtraction/script.js new file mode 100644 index 0000000..f342f48 --- /dev/null +++ b/Wrong Subtraction/script.js @@ -0,0 +1,26 @@ +/* +From Codeforces - +Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. + Tanya subtracts one from a number by the following algorithm: + + if the last digit of the number is non-zero, she decreases the number by one; + if the last digit of the number is zero, she divides the number by 10 (i.e. removes the last digit). + +You are given an integer number n. Tanya will subtract one from it k times. Your task is to print the result after all k subtractions. + +It is guaranteed that the result will be positive integer number. +*/ + +function WrongSubtraction(n, k) { + for (var i = 0; i < k; i++) { + if(n%10 != 0) { + n = n - 1; + } else { + n = n/10; + } + } + + return n; +} + +console.log(WrongSubtraction(1000000000,9)) \ No newline at end of file From 855eed344367ab1065caa7175f5699d5160ac795 Mon Sep 17 00:00:00 2001 From: Soubik Bhui <73220513+sb16072007@users.noreply.github.com> Date: Wed, 30 Dec 2020 19:57:15 +0530 Subject: [PATCH 07/10] Update script.js --- Wrong Subtraction/script.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/Wrong Subtraction/script.js b/Wrong Subtraction/script.js index f342f48..a70d40d 100644 --- a/Wrong Subtraction/script.js +++ b/Wrong Subtraction/script.js @@ -22,5 +22,3 @@ function WrongSubtraction(n, k) { return n; } - -console.log(WrongSubtraction(1000000000,9)) \ No newline at end of file From 95fa5ce6f59d8df68d60551cbb4daffde664d290 Mon Sep 17 00:00:00 2001 From: Soubik Bhui <73220513+sb16072007@users.noreply.github.com> Date: Wed, 30 Dec 2020 20:06:27 +0530 Subject: [PATCH 08/10] Added Translation --- Translation/script.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Translation/script.js diff --git a/Translation/script.js b/Translation/script.js new file mode 100644 index 0000000..94ee35c --- /dev/null +++ b/Translation/script.js @@ -0,0 +1,25 @@ +/* +From CodeForces - +The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly. + +Input +The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. + +Output +If the word t is a word s, written reversely, print YES, otherwise print NO. +*/ + +function Translation(t,s) { + let letters = []; + for(var i = t.length - 1; i >= 0; i--) { + letters.push(t[i]); + } + + let reverse_word_withComma = letters.join(); + let reverse_word = reverse_word_withComma.replaceAll(',',''); + if(reverse_word == s) { + return "YES"; + } else { + return "NO"; + } +} \ No newline at end of file From 2c2a0713be007c54f0f87446765579453d5f094c Mon Sep 17 00:00:00 2001 From: Soubik Bhui Date: Sun, 3 Jan 2021 14:35:57 +0530 Subject: [PATCH 09/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c9f600b..4292dd8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # JavaScript-Algorithms -## Some Javascript Algorithms +## Some Javascript Algorithms and Solutions From b02267cea5d1131b885c29f076203677c4888f51 Mon Sep 17 00:00:00 2001 From: Soubik Bhui Date: Sun, 3 Jan 2021 14:36:15 +0530 Subject: [PATCH 10/10] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4292dd8..94f8278 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # JavaScript-Algorithms -## Some Javascript Algorithms and Solutions +### Some Javascript Algorithms and Solutions