Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions fullstack-cert/js-projects/lab-signal-pattern-detector/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
function findRepeatedPhrases(words, phraseLength) {
const repeatedWordsIndecies = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const repeatedWordsIndecies = []
const repeatedWordsIndices = []


for (let i = 0; i <= words.length - phraseLength; i++) {
for (let j = i + 1; j <= words.length - phraseLength; j++) {
let match = true

for (let k = 0; k < phraseLength; k++) {
if (words[i + k] !== words[j + k]) {
match = false
break
}
}

if (match) {
repeatedWordsIndecies.push(i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
repeatedWordsIndecies.push(i)
repeatedWordsIndices.push(i)

break
}
}
}

return repeatedWordsIndecies
}

function findPalindromeBreaks(words) {
const palindromesBroken = []

for (let i = 0; i < Math.floor(words.length / 2); i++) {
const palindromeIndex = words.length - 1 - i

if (words[i] !== words[palindromeIndex]) {
palindromesBroken.push(i)
}
}

return palindromesBroken
}

function analyseTexts(texts, phraseLength) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function analyseTexts(texts, phraseLength) {
function analyzeTexts(texts, phraseLength) {

let results = []
for (let i = 0; i < texts.length; i++) {
const repeatedPhrases = findRepeatedPhrases(texts[i], phraseLength)
const palindromeBreaks = findPalindromeBreaks(texts[i])

results.push({ repeatedPhrases, palindromeBreaks })
}

return results
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
In this lab, you will create a proofreading tool, a tool that checks text for repeated phrases and palindrome breaks.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In this lab, you will create a proofreading tool, a tool that checks text for repeated phrases and palindrome breaks.
In this lab, you will create a proofreading tool, a tool that checks text for repeated words and palindrome breaks.

what is a palidrome break?


**Objective**: Fulfill the user stories below and get all the tests to pass to complete the lab.

**User Stories**:

1. You should implement `findRepeatedPhrases(words, phraseLength)` - given an array of words and a phrase length, find the starting indices of any repeated word sequences. Use nested loops with early exit `break` flags.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with break there may be the issue that was not practiced in a workshop before now, it's worth to bring up with Naomi as this is not the only lab that uses break (or continue)

anyway, the user story does not give enough infos to know what the function should do

2. You should implement `findPalindromeBreaks(words)` — given an array of words, find the indices where the word-level palindrome is broken.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are not enough details of what the function should do

3. You should implement `analyseTexts(texts, phraseLength)` — run both checks on each text in an array and return an array of result objects.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
3. You should implement `analyseTexts(texts, phraseLength)` — run both checks on each text in an array and return an array of result objects.
3. You should implement `analyzeTexts(texts, phraseLength)` — run both checks on each text in an array and return an array of result objects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean with an array of result objects? does the order matter? please add details