From 0b912a1220615c45b618c814c47cf2d530d815c9 Mon Sep 17 00:00:00 2001 From: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Date: Tue, 5 Mar 2019 07:37:01 -0800 Subject: [PATCH] fix: removed invalid Intermediate solution (#35504) --- .../pig-latin/index.md | 29 +------------------ 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/guide/english/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin/index.md b/guide/english/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin/index.md index a13459a1e5..946beb7ba4 100644 --- a/guide/english/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin/index.md +++ b/guide/english/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/pig-latin/index.md @@ -85,7 +85,7 @@ You will need to use everything you know about string manipulation to get the la * JS String Prototype IndexOf * JS String Prototype Substr -## ![:sunflower:](https://forum.freecodecamp.com/images/emoji/emoji_one/sunflower.png?v=3 ":sunflower:") Intermediate Code Solution #1: +## ![:sunflower:](https://forum.freecodecamp.com/images/emoji/emoji_one/sunflower.png?v=3 ":sunflower:") Intermediate Code Solution: function translatePigLatin(str) { if (str.match(/^[aeiou]/)) return str + "way"; @@ -116,33 +116,6 @@ You will need to use everything you know about string manipulation to get the la * String.prototype.match() * JS String Prototype Substr -## ![:sunflower:](https://forum.freecodecamp.com/images/emoji/emoji_one/sunflower.png?v=3 ":sunflower:") Intermediate Code Solution #2: - - function translatePigLatin(str) { - function check(obj) { - return ['a','i','u','e','o'].indexOf(str.charAt(obj)) == -1 ? check(obj + 1) : obj; - } - - return str.substr(check(0)).concat((check(0) === 0 ? 'w' : str.substr(0, check(0))) + 'ay'); - } - - // test here - translatePigLatin("consonant"); - - -### Code Explanation: - -* This is a declarative as well as recursive approach to this problem. -* `check()` is a function which checks for first letter of string to be in the array of vowels, `['a','i','u','e','o']`. -* In case of consonants, `check()` calls itself on the next characters until finding the first vowel. -* It'll return the index of whatever it finds to be the last initial consonant i.e., Schmidtsville's would be 3. -* Then, letters up until that index are removed from the string and concatenated with either that same chunk of removed string or **w** accordingly, and then **ay** regardless. - -#### Relevant Links - -* JS String Prototype CharAt -* JS String Prototype Concat - ## ![:rotating_light:](https://forum.freecodecamp.com/images/emoji/emoji_one/rotating_light.png?v=3 ":rotating_light:") Advanced Code Solution: function translatePigLatin(str) {