This file contains 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
$(document).ready(function(){ | |
//get the quote api information with Ajax | |
getQuote(); | |
function getQuote(){ | |
$.ajax({ | |
url: "https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies&count=1", | |
type: "GET", | |
data: {}, | |
dataType: "json", | |
beforeSend: function(xhr) { |
This file contains 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
$(document).ready(function(){ | |
var latitude = ''; | |
var longitude = ''; | |
navigator.geolocation.getCurrentPosition(function(position) { | |
latitude = position.coords.latitude; | |
longitude = position.coords.longitude; | |
console.log('lat=' + latitude + ' long=' + longitude); | |
}); | |
}); |
This file contains 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
function whatIsInAName(collection, source) { | |
// What's in a name? | |
var arr = []; | |
// Only change code below this line | |
var sKeyVal = []; | |
sKeyVal.push( Object.keys(source) ); //find the keys in the source | |
sKeyVal.push( Object.values(source) ); //find the values in source | |
var match = 0; | |
This file contains 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
function pairElement(str) { | |
str = str.split(""); | |
var pairs = []; | |
for(var i = 0; i < str.length; i++){ | |
switch (str[i]) { | |
case "C": | |
pairs.push(["C", "G"]); | |
break; | |
case "G": |
This file contains 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
function uniteUnique(arr) { | |
var args = []; | |
//loop over the arguments provided and then loop over each array | |
//within the arguments, check if the value is already in the new | |
//array, if it's not, add it in. | |
for(var i = 0; i < arguments.length; i++){ | |
for(var j = 0; j<arguments[i].length; j++){ | |
if(args.indexOf(arguments[i][j]) == -1){ | |
args.push(arguments[i][j]); | |
} |
This file contains 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
function convertHTML(str) { | |
// :) | |
//create an object to store the html conversions | |
var htmlEntities = { | |
'&' : '&', | |
'<' : '<', | |
'>' : '>', | |
'"' : '"', | |
"'" : ''' | |
}; |
This file contains 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
function spinalCase(str) { | |
// "It's such a fine line between stupid, and clever." | |
// --David St. Hubbins | |
function processStr(match, offset, string){ | |
//if the offset is not the first letter and there isn't already a hyphen, | |
//add a hyphen then change the letter to lowercase | |
if(offset !== 0 && string[offset-1] !== '-'){ | |
return '-' + match.toLowerCase(); | |
} |
This file contains 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
function sumFibs(num) { | |
//set up variables a counter to hold the next Fibonacci number and an | |
//array to hold all the Fibonacci numbers below num. | |
var count = 0; | |
var fib = [1, 1]; | |
//loop through and keep adding Fibonacci numbers to the array until the num is reached | |
for(var i = 0; i<fib.length; i++){ | |
count = fib[i] + fib[i+1]; |
This file contains 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
function sumPrimes(num) { | |
var ints = [2]; //array to hold prime numbers | |
//function to test if a number is a prime | |
function isPrime(test){ | |
for(var i = 2; i < test; i++){ | |
if(test % i == 0){ //if there's no remainder it's not a prime | |
return false; //not a prime number |
This file contains 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
function smallestCommons(arr) { | |
//sort the array ascending, so that a is always the smaller number | |
arr.sort(function(a,b){ | |
return a-b; | |
}); | |
//first find the GCD of the pair of numbers using the Euclidean Algorithm. | |
//return the GCD | |
function gcd(a, b){ | |
var x = a; |
OlderNewer