Last active
April 18, 2025 21:43
-
-
Save alicephieu/8cc896009efd5c169bb94eaee27cac3c to your computer and use it in GitHub Desktop.
Alice Phieu - Watch and Code - Week 2 homework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
***** Answers to question 1 ***** | |
['hi', 'hi']; | |
['bye']; | |
['hi'] | |
['hi', 'bye']; | |
***** Answers to question 2 ***** | |
'hello'; | |
'bye'; | |
***** Answer to question 3 ***** | |
//Define function name | |
function areTheyEqual(arrayOfNumbers) { | |
//Start with the first index, continue and end after the last index | |
for (let i=0; i < arrayOfNumbers.length; i++) { | |
//Step 1: areTheyEqual = 0 | |
//Step 2: Take a number assign it areTheyEqual | |
let numberOne = arrayOfNumbers[i]; | |
//Step 3: Take next number and check if it's equal to areTheyEqual | |
//Step 3a: Check if the next number exists | |
//Step 4: If yes, repeat Step 3 until there are no more numbers | |
//Step 5: If no, produce false, and exit the loop | |
let numberTwo = arrayOfNumbers[i+1]; | |
if (numberOne !== numberTwo && numberTwo !== undefined) { | |
return false; | |
} | |
//Step 6: Produce true after the loop | |
} | |
return true; | |
} | |
***** Answer to question 4 ***** | |
function doesFiveAppearAtLeastTwice(arrayOfNumbers) { | |
//Step 1: Set/Start numberOfFives with 0 | |
let numberOfFives = 0; | |
//Step 2: Start with the first index, continue and end after the last index | |
for (let i=0; i < arrayOfNumbers.length; i++) { | |
if (arrayOfNumbers[i] === 5) { | |
//Step 3: If a 5 exists, increment numberOfFives | |
numberOfFives++; | |
} | |
} | |
//Step 4: If 5 exists at least twice, return true | |
if (numberOfFives >= 2) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment