-
Notifications
You must be signed in to change notification settings - Fork 82
intermediate javascript exercise sols #29
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
naab-c
wants to merge
19
commits into
rithmschool:master
Choose a base branch
from
naab-c: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.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e020f7b
function 1 sol
naab-c abfac49
function 1+2 sol
naab-c 5698a00
function 1+2+3+4 sol
naab-c c1b0bc7
function 1+2+3+4+5 sol
naab-c f6b21f4
recursion 1+2+3 sol
naab-c b4d5310
recursion 1+2+3+4 sol
naab-c a253fe5
recursion 1+2+3+4 sol simple and helper
naab-c 6bd6d7b
recursion 1+2+3+4+6
naab-c 26867d4
recursion 1+2+3+4+6 sol
naab-c 317c8c8
Merge branch 'master' of https://github.com/rithmschool/intermediate_…
naab-c 2cd69a8
loadash 1-15 sol
naab-c 38f8f15
canvas app sol
naab-c d7d53b6
comments fixed
naab-c 58f3863
sol 16-17 lodash
naab-c ab7f4a1
sol 16-17 lodash updated
naab-c a17aad4
call-apply-bind sol
naab-c 3fefe46
Merge branch 'master' of https://github.com/rithmschool/intermediate_…
naab-c c098e3d
prototype exercise sol
naab-c 3e0dffe
assesment hack-snooze partial sol
naab-c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| .row { | ||
| background-color: #f6f6ef; | ||
| } | ||
|
|
||
| .borderless td, .borderless th { | ||
| border: none; | ||
| } | ||
| .navbar { | ||
| background-color: #ff6600; | ||
| margin-bottom: 0; | ||
| } | ||
| .navbar-text p { | ||
| display: inline; | ||
| } | ||
|
|
||
| /*#loggedUser { | ||
| display:inline-block; !important | ||
| vertical-align: middle; !important | ||
| }*/ | ||
|
|
||
| #loggedUser span { | ||
| display: block; | ||
| } | ||
|
|
||
|
|
||
| .formdeco { | ||
| background-color: #f6f6ef; | ||
| padding-top: 10px; | ||
| } | ||
| .noShow { | ||
| /*padding-bottom: 0px;*/ | ||
| display: none; | ||
| } | ||
|
|
||
| .loginOnly { | ||
| display: none; | ||
| } | ||
|
|
||
| li { | ||
| padding: 5px; | ||
| } | ||
| ol { | ||
| padding-top: 0px; | ||
| background-color: #f6f6ef; | ||
| /*text-decoration: none !important; | ||
| color: black !important;*/ | ||
|
|
||
| } | ||
| section + ol { | ||
| margin-top: -20px; | ||
| } | ||
| ol { | ||
| padding-top: 20px; | ||
| } | ||
|
|
||
| .navbar-text span:hover { | ||
| cursor: pointer; | ||
| text-decoration: underline; | ||
| } | ||
|
|
||
| .navbar-right li { | ||
| padding-left: 0px; | ||
| /*margin-right: 10px;*/ | ||
| } | ||
|
|
||
| .navbar ul { | ||
| margin-right: 0px; | ||
| } | ||
|
|
||
| ol a:link { | ||
| text-decoration: none !important; | ||
| /*color: inherit;*/ | ||
| } | ||
|
|
||
| ol a { | ||
| color: black !important; | ||
| } | ||
|
|
||
| span.cuthead { | ||
| font: 8pt Verdana, Geneva, sans-serif !important; | ||
| /*font: italic small-caps normal 13px/150% Arial, Helvetica, sans-serif; | ||
| font-size: 8pt !important; | ||
| font-family: Verdana, Geneva, sans-serif !important;*/ | ||
| /*color: #828282;*/ | ||
|
|
||
| } | ||
|
|
||
| span.cuthead:hover { | ||
| cursor: pointer; | ||
| display: inline-block; | ||
| text-decoration: underline; | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| $(document).ready(function() { | ||
|
|
||
| // do this | ||
| fetchTopTwentyStories(); | ||
|
|
||
| var signUp; | ||
|
|
||
|
|
||
| $('#login').on('click', function(event) { | ||
| if ($( this ).text() === "logout") { | ||
| var email = $( ".navbar-right li" ).eq(1).text(); | ||
| // remove text on right | ||
| $( ".navbar-right li" ).each(function() { | ||
| $( this ).remove(); | ||
| }); | ||
|
|
||
| // toggle favorite | ||
| $('.navbar-text text').eq(1).toggleClass('loginOnly'); | ||
| $('#fav').toggleClass('loginOnly'); | ||
| //$('.loginOnly').toggleClass('loginOnly'); | ||
|
|
||
| // remove auth token from local storage | ||
| localStorage.removeItem(email); | ||
|
|
||
| // change text back to login | ||
| $( this ).text("login").wrapInner("<strong />"); | ||
|
|
||
| // empty stories list display | ||
| $("ol").empty(); | ||
| } | ||
| else { | ||
| $('section').toggleClass('noShow'); | ||
| signUp = false; | ||
| } | ||
| }); | ||
|
|
||
| $('#signup').on('click', function(event) { | ||
| $('section').toggleClass('noShow'); | ||
| signUp = true; | ||
| }); | ||
|
|
||
| $('.form-horizontal').on('submit', function(event) { | ||
| if(signUp) { | ||
| loginOrSignUp("signup"); | ||
| } | ||
| else { | ||
| loginOrSignUp("login"); | ||
| } | ||
|
|
||
| $('section').toggleClass('noShow'); | ||
| event.preventDefault(); | ||
| }); | ||
|
|
||
| $('#fav').on("click", function(e) { | ||
| if ($( this ).text() === "all") { | ||
| $( "li span" ).each(function( index ) { | ||
| if($( this ).hasClass('glyphicon-star-empty') ) { | ||
| $( this ).parent().show(); | ||
| } | ||
| }); | ||
| $( this ).text("favorites").wrapInner("<strong />"); | ||
| } | ||
| else if ( $( this ).text() === "favorites" ) { | ||
| $( "li span" ).each(function( index ) { | ||
| if($( this ).hasClass('glyphicon-star-empty') ) { | ||
| $( this ).parent().hide(); | ||
| } | ||
| }); | ||
| $( this ).text("all").wrapInner("<strong />"); | ||
|
|
||
| } | ||
|
|
||
| }); | ||
|
|
||
| $("ol").on("click", ".glyphicon", function(e) { | ||
| if( $(e.target).hasClass('glyphicon-star-empty') ) { | ||
|
|
||
| $(e.target).toggleClass('glyphicon-star-empty glyphicon-star'); | ||
| } | ||
| else { | ||
| $(e.target).toggleClass('glyphicon-star glyphicon-star-empty'); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| function fetchTopTwentyStories() { | ||
| $.get("https://hacker-news.firebaseio.com/v0/topstories.json") | ||
| .then(function(stories) { | ||
| return stories.slice(0, 20); | ||
| }) | ||
| .then(function(tStories) { | ||
| tStories.forEach(function(element) { | ||
| $.get('https://hacker-news.firebaseio.com/v0/item/' + element + '.json') | ||
| .then(function(storyDetail) { | ||
| if ('url' in storyDetail) { | ||
| var cutUrl = ""; | ||
| var iUrl = storyDetail.url; | ||
| if (iUrl.includes("www.")) { | ||
| cutUrl = iUrl.split('www.')[1].split('/')[0].split('.').slice(-2).join('.'); | ||
| } | ||
| else { | ||
| cutUrl = storyDetail.url.split('//')[1].split('/')[0]; | ||
| if (cutUrl.match(/(.*\.)+(.*\.)+.*/g)) { | ||
| cutUrl = cutUrl.split('.').slice(-2).join('.'); | ||
| } | ||
| } | ||
| var element = '<li><span class="glyphicon glyphicon-star-empty' + | ||
| '"></span> <a href="' + storyDetail.url + '"> ' + storyDetail.title + '</a> (' + | ||
| '<span class="cuthead"><a href="from?site=' + cutUrl + '"><span>' + cutUrl + | ||
| '</span></a></span>)</li>'; | ||
| $('ol').append(element); | ||
| } | ||
| }) | ||
| .fail(function(error) { | ||
| console.warn("Isuue encountered in item fetch api"); | ||
| }); | ||
| }); | ||
| }) | ||
| .fail(function(error) { | ||
| console.warn("Isuue encountered in top stories fetch api"); | ||
| }); | ||
| } | ||
|
|
||
| function loginOrSignUp(str) { | ||
| var email = $('#email').val(); | ||
| var password = $('#password').val(); | ||
| $.ajax({ | ||
| method: "POST", | ||
| headers: { | ||
| "Content-Type": "application/json" | ||
| }, | ||
|
|
||
| url: 'https://hn-favorites.herokuapp.com/' + str + '', | ||
| data: JSON.stringify({ | ||
| email: email, | ||
| password: password | ||
| }) | ||
| }) | ||
| .then(function(data) { | ||
| if ( data.auth_token.length > 0 && data.auth_token.includes('.') ) { | ||
| alert(str + " successful."); | ||
| // save the auth token in local storage | ||
| localStorage.setItem(email, data.auth_token); | ||
| $('.form-horizontal').each(function() { | ||
| this.reset(); | ||
| }); | ||
|
|
||
| // toggle login to logout and add text logged in as on right nav | ||
| // and show the favorites tab/icon | ||
| if(str === "login") { | ||
| $('.navbar-text text').eq(1).toggleClass('loginOnly'); | ||
| $('#fav').toggleClass('loginOnly'); | ||
| //$('.loginOnly').toggleClass('loginOnly'); | ||
| var element = '<li><b>Logged in as:</b></li>' + | ||
| '<li><b>' + email + '</b></li>'; | ||
| $('.navbar-right').append(element); | ||
| $('#login').text("logout").wrapInner("<strong />"); | ||
| } | ||
| } | ||
| }) | ||
| .fail(function(err) { | ||
| if( 'status' in err && 'statusText' in err ) | ||
| // if( err.status !== undefined && err.statusText !== undefined ) | ||
| alert(str + " not successful. " + err.status + ": " + err.statusText); | ||
| else | ||
| alert(str + " not successful."); | ||
| }); | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| var obj = { | ||
| fullName: "Harry Potter", | ||
| person: { | ||
| sayHi: function(){ | ||
| return "This person's name is " + this.fullName | ||
| }.bind(obj) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| function sumEvenArguments() { | ||
| var args = [].slice.call(arguments); | ||
|
|
||
| return args.reduce(function(acc, nextValue) { | ||
| if( nextValue % 2 === 0 ) acc += nextValue; | ||
| return acc; | ||
| }, 0); | ||
|
|
||
| // return args.filter(function(a) { return (a % 2) === 0; }).reduce(function(acc, nextValue) { | ||
| // return acc + nextValue | ||
| // }, 0); | ||
| } | ||
|
|
||
| function arrayFrom() { | ||
| return [].slice.call(arguments); | ||
| } | ||
|
|
||
| function invokeMax(fn, num) { | ||
| var count = num; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you count down, you don't even need to copy the variable. Numbers are not reference types. |
||
| return function innerFunction(){ | ||
| if (count <= 0) { | ||
| return "Maxed Out!"; | ||
| } | ||
| else { | ||
| count--; | ||
| return fn.apply(this, arguments); | ||
|
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| function guessingGame(amount) { | ||
| var answer = Math.floor(Math.random() * 11); | ||
| var guesses = 0; | ||
| return function innerFunction(guess) { | ||
| if(guesses <= amount) { | ||
| if(guesses === amount && guess !== answer) { | ||
| guesses++; | ||
| return "No more guesses the answer was " + answer; | ||
| } | ||
| if(guess === answer) { | ||
| guesses = amount + 1; | ||
| return "You got it!"; | ||
| } | ||
| if (guess < answer) { | ||
| guesses++; | ||
| return "You're too low!"; | ||
| } | ||
| if (guess > answer) { | ||
| guesses++; | ||
| return "You're too high!"; | ||
| } | ||
| } | ||
| else { | ||
| return "You are all done playing!"; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work because obj won't be defined yet. Here is a work around: