Created
September 27, 2017 03:32
-
-
Save jjanusch/5a53ff08fadf1718107271b873ffa078 to your computer and use it in GitHub Desktop.
Finds NHL players without vowels in their last name
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
<html> | |
<body> | |
<ol id="players"> | |
</ol> | |
<script | |
src="https://code.jquery.com/jquery-3.2.1.min.js" | |
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" | |
crossorigin="anonymous"></script> | |
<script type="text/javascript"> | |
var letters = "abcdefghijklmnopqrstuvwxyz".split(''), | |
vowels = 'aeiouy'.split(''), | |
playersWithoutVowels = [], | |
currentIndex = 0; | |
processLetter('a'); | |
function processLetter(letter) { | |
$.ajax({ | |
url: 'https://cors-anywhere.herokuapp.com/https://www.hockey-reference.com/players/' + letter + '/', | |
type: 'GET', | |
crossDomain: true, | |
dataType: 'html', | |
success: function (response) { | |
processHtml(response); | |
}, | |
error: function () { | |
if (currentIndex < letters.length - 1) { | |
processLetter(letters[++currentIndex]); | |
} else { | |
writeOutput(); | |
} | |
} | |
}); | |
} | |
function processHtml(html) { | |
var $el = $(html); | |
$el.find('#div_players > p a').each(function () { | |
var nameArray = $(this).text().split(' '); | |
nameArray.shift(); | |
var lastName = nameArray.join(' ').toLowerCase(); | |
var letterFound = vowels.some(function (letter) { | |
return lastName.indexOf(letter) >= 0; | |
}); | |
if (!letterFound) { | |
playersWithoutVowels.push($(this).text()); | |
} | |
}); | |
console.log('Parsed Letter: ' + letters[currentIndex] + ' -- Total Found: ' + playersWithoutVowels.length); | |
if (currentIndex < letters.length - 1) { | |
processLetter(letters[++currentIndex]); | |
} else { | |
writeOutput(); | |
} | |
} | |
function writeOutput() { | |
playersWithoutVowels.forEach(function (player) { | |
$('#players').append($('<li>').text(player)); | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment