From 66f34a9b5f879f2a5e89ef0e934657f4b0c075c7 Mon Sep 17 00:00:00 2001 From: yuliu2016 Date: Mon, 30 Oct 2017 22:45:42 -0400 Subject: [PATCH 1/2] Add JS Extensions --- Check for Palindromes => Check for Palindromes.js | 0 Chunky Monkey => Chunky Monkey.js | 0 Confirm the Ending => Confirm the Ending.js | 0 Counting Cards => Counting Cards.js | 0 Factorialize a Number => Factorialize a Number.js | 0 Falsy Bouncer => Falsy Bouncer.js | 0 ...ngest Word in a String => Find the Longest Word in a String.js | 0 Mutations => Mutations.js | 0 Profile Lookup => Profile Lookup.js | 0 ...a string repeat a string => Repeat a string repeat a string.js | 0 ...rgest Numbers in Arrays => Return Largest Numbers in Arrays.js | 0 Reverse a String => Reverse a String.js | 0 Seek and Destroy => Seek and Destroy.js | 0 Title Case a Sentence => Title Case a Sentence.js | 0 14 files changed, 0 insertions(+), 0 deletions(-) rename Check for Palindromes => Check for Palindromes.js (100%) rename Chunky Monkey => Chunky Monkey.js (100%) rename Confirm the Ending => Confirm the Ending.js (100%) rename Counting Cards => Counting Cards.js (100%) rename Factorialize a Number => Factorialize a Number.js (100%) rename Falsy Bouncer => Falsy Bouncer.js (100%) rename Find the Longest Word in a String => Find the Longest Word in a String.js (100%) rename Mutations => Mutations.js (100%) rename Profile Lookup => Profile Lookup.js (100%) rename Repeat a string repeat a string => Repeat a string repeat a string.js (100%) rename Return Largest Numbers in Arrays => Return Largest Numbers in Arrays.js (100%) rename Reverse a String => Reverse a String.js (100%) rename Seek and Destroy => Seek and Destroy.js (100%) rename Title Case a Sentence => Title Case a Sentence.js (100%) diff --git a/Check for Palindromes b/Check for Palindromes.js similarity index 100% rename from Check for Palindromes rename to Check for Palindromes.js diff --git a/Chunky Monkey b/Chunky Monkey.js similarity index 100% rename from Chunky Monkey rename to Chunky Monkey.js diff --git a/Confirm the Ending b/Confirm the Ending.js similarity index 100% rename from Confirm the Ending rename to Confirm the Ending.js diff --git a/Counting Cards b/Counting Cards.js similarity index 100% rename from Counting Cards rename to Counting Cards.js diff --git a/Factorialize a Number b/Factorialize a Number.js similarity index 100% rename from Factorialize a Number rename to Factorialize a Number.js diff --git a/Falsy Bouncer b/Falsy Bouncer.js similarity index 100% rename from Falsy Bouncer rename to Falsy Bouncer.js diff --git a/Find the Longest Word in a String b/Find the Longest Word in a String.js similarity index 100% rename from Find the Longest Word in a String rename to Find the Longest Word in a String.js diff --git a/Mutations b/Mutations.js similarity index 100% rename from Mutations rename to Mutations.js diff --git a/Profile Lookup b/Profile Lookup.js similarity index 100% rename from Profile Lookup rename to Profile Lookup.js diff --git a/Repeat a string repeat a string b/Repeat a string repeat a string.js similarity index 100% rename from Repeat a string repeat a string rename to Repeat a string repeat a string.js diff --git a/Return Largest Numbers in Arrays b/Return Largest Numbers in Arrays.js similarity index 100% rename from Return Largest Numbers in Arrays rename to Return Largest Numbers in Arrays.js diff --git a/Reverse a String b/Reverse a String.js similarity index 100% rename from Reverse a String rename to Reverse a String.js diff --git a/Seek and Destroy b/Seek and Destroy.js similarity index 100% rename from Seek and Destroy rename to Seek and Destroy.js diff --git a/Title Case a Sentence b/Title Case a Sentence.js similarity index 100% rename from Title Case a Sentence rename to Title Case a Sentence.js From e3c06071d421eff3c54166b0a67d07451cd98a60 Mon Sep 17 00:00:00 2001 From: yuliu2016 Date: Mon, 30 Oct 2017 23:26:17 -0400 Subject: [PATCH 2/2] Changed Some Codes --- Check for Palindromes.js | 41 ++++++++++++++++++---------- Chunky Monkey.js | 19 ++++++------- Confirm the Ending.js | 30 ++++++++++---------- Counting Cards.js | 32 +++++++++++----------- Factorialize a Number.js | 28 ++++++++++++------- Falsy Bouncer.js | 10 +++---- Find the Longest Word in a String.js | 41 +++++++++++++++++----------- Mutations.js | 38 +++++++++++++------------- Profile Lookup.js | 24 ++++++++-------- Repeat a string repeat a string.js | 33 ++++++++++------------ Return Largest Numbers in Arrays.js | 30 ++++++++++---------- Reverse a String.js | 14 +++++----- Seek and Destroy.js | 18 ++++++------ Title Case a Sentence.js | 34 +++++++++++------------ 14 files changed, 205 insertions(+), 187 deletions(-) diff --git a/Check for Palindromes.js b/Check for Palindromes.js index 36ca12c..80f0bdc 100644 --- a/Check for Palindromes.js +++ b/Check for Palindromes.js @@ -1,21 +1,32 @@ function palindrome(str) { - str=str.replace(/[^0-9a-z]/gi, ''); - str=str.toLowerCase(); - - var stringArr=[]; - var backwardString=""; - - stringArr=str.split(""); - stringArr=stringArr.reverse(); -backwardString=stringArr.join(""); - - if (backwardString===str){ - return true; -} else { - return false; -} + str = str.replace(/[^0-9a-z]/gi, ''); + str = str.toLowerCase(); + + var stringArr = []; + var backwardString =""; + + stringArr=str.split(""); + stringArr=stringArr.reverse(); + backwardString=stringArr.join(""); + + if (backwardString===str){ + return true; + } else { + return false; + } } palindrome("eye"); + + +/*PP's solution: + +function palindrome(s) { +return s == "" || (s.charAt(0) === s.charAt(s.length - 1) && palindrome(s.substring(1, s.length - 2))) +} + +Note: it doesn't ignore special characters + +*/ diff --git a/Chunky Monkey.js b/Chunky Monkey.js index 3207147..4ee5b3c 100644 --- a/Chunky Monkey.js +++ b/Chunky Monkey.js @@ -1,14 +1,13 @@ function chunkArrayInGroups(arr, size) { - var newArr=[]; - var newSubArr=[]; - - for (i=0;i=2&&card<=6){ - count++; - } else if (card>=7&&card<=9){ - - } else { - count--; - - } - - if (count>0){ - return count+" "+ "Bet"; - } else { - return count+" "+ "Hold"; -} + + + if (card>=2&&card<=6){ + count++; + } else if (card>=7&&card<=9){ + + } else { + count--; + + } + + if (count>0){ + return count+" "+ "Bet"; + } else { + return count+" "+ "Hold"; + } } diff --git a/Factorialize a Number.js b/Factorialize a Number.js index c839d0a..3f1092f 100644 --- a/Factorialize a Number.js +++ b/Factorialize a Number.js @@ -1,15 +1,23 @@ function factorialize(num) { - if (num===0){ - return 1; - } else { - for (i=num-1;i>0;i--){ - num=num*i; - - } - - return num; - } + if (num===0){ + return 1; + } else { + for (i=num-1;i>0;i--){ + num=num*i; + + } + + return num; + } } factorialize(5); + +/*PP's solution: + +function factorialize(num) { + return num <= 0 ? 1 : num * factorialize(num - 1); +} + +*/ diff --git a/Falsy Bouncer.js b/Falsy Bouncer.js index 70ceb24..4b8368a 100644 --- a/Falsy Bouncer.js +++ b/Falsy Bouncer.js @@ -1,10 +1,10 @@ function bouncer(arr) { - - - return arr.filter(Boolean); - - + + + return arr.filter(Boolean); + + } bouncer([7, "ate", "", false, 9]); diff --git a/Find the Longest Word in a String.js b/Find the Longest Word in a String.js index 6a993d7..c64b1ad 100644 --- a/Find the Longest Word in a String.js +++ b/Find the Longest Word in a String.js @@ -1,20 +1,29 @@ function findLongestWord(str) { - var length=0; - var result=0; - var arr=[]; - arr=str.split(" "); - - for (i=0;iresult){ - result=length; - } - - } -return result; - - + var length = 0; + var result = 0; + var arr = []; + arr = str.split(" "); + + for (i = 0; i < arr.length; i++){ + length = arr[i].length; + + if (length > result){ + result = length; + } + + } + return result; } findLongestWord("The quick brown fox jumped over the lazy dog"); + + +/*PP's solution: + +function findLongestWord(str) { + max = 0; + for (i in str.split(" ")) if (max < i.length) max = i.length; + return max; +} + +*/ diff --git a/Mutations.js b/Mutations.js index 45fd24a..a9a8c1e 100644 --- a/Mutations.js +++ b/Mutations.js @@ -1,24 +1,24 @@ function mutation(arr) { - var letterFirst=""; - var letterSecond=""; - var count=0; - - for (i=0;i< arr[1].length;i++){ - count=0; - letterFirst=arr[1].slice(i,i+1); - - for (j=0;jresult){ - result=number; - - } + var number=0; + var result=0; + var newArr=[]; + for (i=0;iresult){ + result=number; + + } + } + newArr[i]=result; } - newArr[i]=result; - } return newArr; } diff --git a/Reverse a String.js b/Reverse a String.js index 689514f..3073019 100644 --- a/Reverse a String.js +++ b/Reverse a String.js @@ -1,13 +1,13 @@ function reverseString(str) { - var stringArr=[]; - - - stringArr=str.split(""); - stringArr=stringArr.reverse(); - return stringArr.join(""); + var stringArr=[]; -} + stringArr=str.split(""); + stringArr=stringArr.reverse(); + return stringArr.join(""); + + +} reverseString("hello"); diff --git a/Seek and Destroy.js b/Seek and Destroy.js index 8517a76..777ae5c 100644 --- a/Seek and Destroy.js +++ b/Seek and Destroy.js @@ -2,15 +2,15 @@ function destroyer(arr) { var newArray = Array.prototype.slice.call(arguments); - - for (i=0;i