From 3f21f0b83ca719cc6e1b9dab8cb01a0b754196e0 Mon Sep 17 00:00:00 2001 From: wenhao Date: Tue, 27 Feb 2018 21:26:17 +0800 Subject: [PATCH] Compeleted assignment --- js/findLongestWord.js | 14 ++++++++++++++ js/isCharacterAVowel.js | 12 ++++++++++++ js/isPrime.js | 21 +++++++++++++++++++++ js/letterCount.js | 25 +++++++++++++++++++++++++ js/maxOfThree.js | 21 +++++++++++++++++++++ js/merge.js | 24 ++++++++++++++++++++++++ js/numSquare.js | 0 js/primes.js | 34 ++++++++++++++++++++++++++++++++++ js/reverseString.js | 14 ++++++++++++++ js/sillySum.js | 13 +++++++++++++ js/sumArray.js | 19 +++++++++++++++++++ 11 files changed, 197 insertions(+) create mode 100644 js/findLongestWord.js create mode 100644 js/isCharacterAVowel.js create mode 100644 js/maxOfThree.js delete mode 100644 js/numSquare.js create mode 100644 js/reverseString.js create mode 100644 js/sumArray.js diff --git a/js/findLongestWord.js b/js/findLongestWord.js new file mode 100644 index 0000000..8edb391 --- /dev/null +++ b/js/findLongestWord.js @@ -0,0 +1,14 @@ +/** +Write a function findLongestWord that takes an array of words and returns the length of the longest word in the array. +*/ + +function findLongestWord(wordsArray){ + var maxLength = 0; + for(var i=0;imaxLength){ + maxLength=currLength; + } + } + return maxLength; +} \ No newline at end of file diff --git a/js/isCharacterAVowel.js b/js/isCharacterAVowel.js new file mode 100644 index 0000000..fe18ada --- /dev/null +++ b/js/isCharacterAVowel.js @@ -0,0 +1,12 @@ +/** +Write a function isCharacterAVowel that takes a character (i.e. a string of length 1) and returns true if it is a vowel and false, otherwise. +*/ + +function isCharacterAVowel(char){ + if(char=="a"||char=="e"||char=="i"||char=="o"||char=="u"){ + console.log(true); + } + else{ + console.log(false); + } +} diff --git a/js/isPrime.js b/js/isPrime.js index e69de29..be5e03e 100644 --- a/js/isPrime.js +++ b/js/isPrime.js @@ -0,0 +1,21 @@ +/** +Create a function to return true or false if a number passed in a prime number. +*/ + +function isPrime(num){ + //prime numbers are greater than 1 + if(num>1){ + for(var i=2;i1){ + for(var i=2;i=0;i--){ + //Starting point of loop corresponds to the last character + newStr += inputString[i]; + } + return console.log(newString); +} diff --git a/js/sillySum.js b/js/sillySum.js index e69de29..7d8540d 100644 --- a/js/sillySum.js +++ b/js/sillySum.js @@ -0,0 +1,13 @@ +/** +Write a function that takes an array of numbers, and returns the sum of each number multiplied by its index +*/ + +function sillySum(array){ + var output = 0; + var currSum = 0; + for(var i=0;i