diff --git a/StockBehavior.js b/StockBehavior.js new file mode 100644 index 0000000..2cb7be3 --- /dev/null +++ b/StockBehavior.js @@ -0,0 +1,27 @@ +//The array stocks stores the behavior of stocks for one year. +//The numbers in the array represent percentages. + +let stocks = [ 5, 5,5,5] + + +//A peak is when the percentage on the left of a given month M is less and the +//percentage on the right of month M is greater. For example, the list given above, contains +//three peaks, they are 6, 8, and 10 (positions 1, 5 and 9 respectively) +// Complete function getPeaks so that it returns an array containing all the locations +// of all peaks that a exists in the parameter array named list. +// If there are no peaks, this function should return an empty array ([]) +function getPeaks(list){ + let finishedarray = []; + for (let i = 0; i < list.length-1; i++) { + // console.log(`i is ${i}, arrindex is ${list[i]}, before, ${list[i-1]}, after ${list[i+1]}`) + if (list[i] > list[i - 1] && list[i] > list[i+1] ) { + finishedarray.push(i); + } + } + return finishedarray; +} + +// for the array stocks shown above, getPeaks should return [1, 5, 9] +// WRITE CODE TO TEST YOUR FUNCTION HERE. + +console.log(getPeaks(stocks)) \ No newline at end of file diff --git a/StringChanllenge.js b/StringChanllenge.js new file mode 100644 index 0000000..92f6cea --- /dev/null +++ b/StringChanllenge.js @@ -0,0 +1,56 @@ +/* + QUOTE: I have a dream that my four little children will one day live + in a nation where they will not be judged by the color of + their skin but by the content of their character. +*/ +let meow = "I have a dream that my four little children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character." +// Function getFrequency takes as parameters two strings, text and token. +// This function needs to return the number of times a token accurs in text +// For example, if this function is tested with above quote and token is +// "will", then this function should return 2 becuase "will" occurs twice in +// the text +function getFrequency(text, token) { + let count = 0; + let words = text.split(" "); // Changed from text.split("") + for (let i=0; i s.length > 0); + const lowercaseWords = words.map(w => w.toLowerCase()); + const lowerCaseWord = word.toLowerCase(); + + if (lowercaseWords.includes(lowerCaseWord)) { + return word.split("").join(","); + } else { + return "Word not found"; + } +} + +console.log(spellWord(meow, "children")) + +// write code to test your functions \ No newline at end of file diff --git a/problem1.js b/problem1.js new file mode 100644 index 0000000..cca12f5 --- /dev/null +++ b/problem1.js @@ -0,0 +1,53 @@ + + +// Function computeAverage() is complete. This function +// takes an array of test named scores and two integers, from and to. +// computeScores returns the average of all the scores starting at +// from and ending at to, inclusive +function computeScores(scores, from, to) +{ + //DO NOT WRITE ANY CODE HERE + let sum = 0; + let average =0; + for(let i=from; i<=to; i++) + { + sum = sum + scores[i] + } + + average = sum/(to-from+1) + return average +} + + + +// Function getRange() is complete. This function +// takes an array of test scores and two integers, from and to. +// getRange returns a string consisting of all the scores from scores +// starting at from and ending at to, inclusive separated by a space +function getRange(scores, from, to) +{ + //DO NOT WRITE ANY CODE HERE + let s=""; + for(let i=from; i<=to; i++) + { + s = s + scores[i] +" " + } + + return s +} + +// ======= Your task is specified in the WORD DOCUMENT ================ + + +let scores = [95, 100,80, 80, 100, 80, 60, 80, 90] +let scores2 = [95, 60, 80, 80, 50, 80, 60, 80, 90] +let scores3 = [95, 100, 75, 80, 80, 80, 60, 80, 75] + +console.log(`Scores: ${getRange(scores, 2, 5)}`) +console.log(`Average:${computeScores(scores, 2, 5)}`) +console.log() +console.log(`Scores: ${getRange(scores2, 4, 8)}`) +console.log(`Average:${computeScores(scores2, 4, 8)}`) +console.log() +console.log(`Scores: ${getRange(scores3, 0, 8)}`) +console.log(`Average:${computeScores(scores3, 0, 8)}`) \ No newline at end of file diff --git a/problem2.js b/problem2.js new file mode 100644 index 0000000..f1d12d0 --- /dev/null +++ b/problem2.js @@ -0,0 +1,101 @@ +//Function displayList is complete +//Function displayList returns a string (a list of) of all test scores +//stored in the parameter array named scores +function displayList(scores) +{ + let s = "" + for(let loc=0; loc