- Notifications
You must be signed in to change notification settings - Fork5.8k
Lab - basic algorithms in JS#3569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
alexandra-junges wants to merge3 commits intoironhack-labs:masterChoose a base branch fromalexandra-junges:master
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
75 changes: 74 additions & 1 deletionindex.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,80 @@ | ||
| // Iteration 1: Names and Input | ||
| const hacker1 = "Alexandra"; | ||
| const hacker2 = "Erica"; | ||
| console.log(`The driver's name is ${hacker1}`); | ||
| console.log(`The navigator's name is ${hacker2}`); | ||
| // Iteration 2: Conditionals | ||
| if (hacker1.length > hacker2.length) { | ||
| console.log(`The driver has the longest name, it has ${hacker1.length} characters.`); | ||
| } else if (hacker2.length > hacker1.length) { | ||
| console.log(`It seems that the navigator has the longest name, it has ${hacker2.length} characters.`); | ||
| } else if (hacker1.length === hacker2.length) { | ||
| console.log(`Wow, you both have equally long names, ${hacker1.length} characters!.`); | ||
| } | ||
| // Iteration 3: Loops | ||
| //3.1 | ||
| let capitalized = '' | ||
| let spaceBetween = '' | ||
| for(let i=0; i < hacker1.length; i++) { | ||
| capitalized += hacker1[i].toUpperCase(); | ||
| spaceBetween = capitalized.split('').join(' '); | ||
| } | ||
| console.log(spaceBetween); | ||
| //3.2 | ||
| let reversedWord = '' | ||
| for(let i=hacker2.length - 1; i >= 0; i--) { | ||
| reversedWord += hacker2[i]; | ||
| } | ||
| console.log(reversedWord); | ||
| 3.3 | ||
| const driver = hacker1.toLowerCase(); | ||
| const navigator = hacker2.toLowerCase(); | ||
| if(navigator.localeCompare(driver) === 1) { | ||
| console.log("The driver's name goes first."); | ||
| } else if (navigator.localeCompare(driver) === -1) { | ||
| console.log("Yo, the navigator goes first, definitely."); | ||
| } else if (navigator.localeCompare(driver) === 0) { | ||
| console.log("What?! You both have the same name?"); | ||
| } | ||
| //Bonus 1: | ||
| const longText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas tincidunt ac tortor in faucibus. Cras euismod urna ac purus convallis porttitor. Nam dapibus arcu nulla, vel faucibus est viverra vel. Vivamus eget porttitor arcu. Duis dolor ex, tempus convallis euismod a, consectetur scelerisque sem. Ut vulputate ipsum condimentum nunc eleifend, ut sollicitudin ligula egestas. Quisque cursus mauris augue, in pulvinar diam finibus ac. Nunc aliquam tincidunt lacus, non pellentesque est hendrerit sit amet. Duis ut arcu sapien. Nullam porttitor rutrum tortor sit amet euismod. Quisque nunc nisl, condimentum in tellus eu, feugiat fringilla enim. Vestibulum est eros, ornare eu diam nec, dapibus vehicula diam. Fusce gravida ante eget lectus posuere, at hendrerit erat sodales. Morbi rhoncus efficitur nunc, in euismod sapien malesuada ut. Phasellus eu porta nisl, a lacinia neque. Ut aliquet lectus eget purus tincidunt placerat vel et ipsum. Fusce lacus ante, sollicitudin vitae ultricies in, dignissim sed sem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Duis tincidunt libero eu eleifend semper. Vivamus blandit mauris quis diam dapibus, sed scelerisque tellus tincidunt. Donec molestie vestibulum fermentum. Praesent ipsum turpis, faucibus ut pulvinar nec, posuere et nulla. Fusce molestie at metus eu suscipit. Cras at dapibus purus. Duis nec eleifend purus. Duis nec quam elit. Nulla facilisi. Nunc sit amet ligula pharetra, euismod arcu id, porta dolor. Integer id tempor eros. Aenean semper, elit vel cursus tempus, erat justo faucibus odio, id posuere erat nibh eget mauris. Aenean non dolor nunc. Pellentesque risus nisl, maximus vitae mi a, congue consequat dolor. Vestibulum dui eros, congue quis sapien eu, tristique lacinia nisi. Curabitur augue purus, lacinia eu placerat at, auctor nec neque. Aenean ac accumsan purus. Aliquam odio tellus, vulputate et erat eu, consectetur maximus sapien. Proin ac suscipit ipsum. Maecenas euismod, lectus eget aliquet accumsan, nunc arcu porttitor justo, et feugiat dui massa quis neque. Morbi eget tempus dui. Quisque at velit nibh. Ut dolor nisi, dapibus sit amet diam vel, lobortis consequat lectus." | ||
| let countStrings = 0; | ||
| let countEt = 0 | ||
| for(let i=0; i < longText.length; i++) { | ||
| if(longText[i] === " "){ | ||
| countStrings += 1; | ||
| } | ||
| else if(longText[i] + longText[i + 1] === "et") { | ||
| countEt++; | ||
| } | ||
| } | ||
| console.log(countStrings); | ||
| console.log(countEt); | ||
| //Bonus 2 | ||
| const phraseToCheck = "race car"; // "stack cats" , | ||
| let phrase = phraseToCheck.toLowerCase(); | ||
| let reverseString = ""; | ||
| for(let i=phrase.length -1 ; i >= 0 ; i--) { | ||
| reverseString += phrase[i]; | ||
| } | ||
| if(phrase === reverseString) { | ||
| console.log(`${phrase}, it's a Palindrome.`) | ||
| } else { | ||
| console.log(`${phrase}, it's not a Poliandrome.`) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.