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 Rabbit(adjective) { | |
this.adjective = adjective; | |
this.describeMyself = function() { | |
console.log("I am a " + this.adjective + " rabbit"); | |
}; | |
} | |
// now we can easily make all of our rabbits | |
var rabbit1 = new Rabbit("fluffy"); |
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 Circle (radius) { | |
this.radius = radius; | |
this.area = function () { | |
return Math.PI * this.radius * this.radius; | |
}; | |
// define a perimeter method here | |
this.perimeter = function () { | |
return 2 * Math.PI * this.radius; | |
} |
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
var bob = { | |
firstName: "Bob", | |
lastName: "Jones", | |
phoneNumber: "(650) 777-7777", | |
email: "bob.jones@example.com" | |
}; | |
var mary = { | |
firstName: "Mary", | |
lastName: "Johnson", |
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 longestConsec(strarr, k) { | |
var longest = ""; | |
for(var i=0;k>0 && i<=strarr.length-k;i++){ | |
var tempArray = strarr.slice(i,i+k); | |
var tempStr = tempArray.join(""); | |
if(tempStr.length > longest.length){ | |
longest = tempStr; | |
} | |
} | |
return longest; |
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 getIndexToIns(arr, num) { | |
arr.push(num); // first we add a number in the array | |
arr.sort(function(a, b) { // then we sort the array in ascending order | |
return a-b; | |
}); | |
return arr.indexOf(num); //then we return the index of the num added to the array | |
} |
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
var nums = [1,2,34,54,55,34,32,11,19,17,54,66,13]; | |
var evens = []; | |
var odds = []; | |
var evenNumbers = function(nums) { | |
for (var i = 0; i < nums.length; i++) { | |
if ((nums[i] % 2) != 1) { | |
evens.push(nums[i]); | |
console.log(evens); |
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
var bills = [50.23, 19.12, 34.01, 100.11, 12.15, 9.90, | |
29.11, 12.99, 10.00, 99.22, 102.20, 100.10, 6.77, 2.22]; | |
// your code goes here | |
var totals = bills.map(function(bill){ | |
bill = bill * 0.15 + bill; | |
return Number(bill.toFixed(2)); | |
}); | |
console.log(totals); |
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
// create your Animal class here | |
function Animal(name, numLegs) { | |
this.name = name; | |
this.numLegs = numLegs; | |
} | |
// create the sayName method for Animal | |
Animal.prototype.sayName = function() { | |
console.log("Hi my name is " + this.name); |
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
var myStringArray = ["Hello","World"]; | |
var arrayLength = myStringArray.length; | |
for (var i = 0; i < arrayLength; i++) { | |
alert(myStringArray[i]); | |
//Do something | |
} | |
======================================= | |
Array.prototype.foo = "foo!"; | |
var array = ['a', 'b', 'c']; |
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 findLongestWord(str) { | |
var splitter = str.split(' '); | |
splitter.sort(function(a, b){ | |
return b.length - a.length; | |
}); | |
return splitter[0].length; | |
} | |
findLongestWord("The quick brown fox jumped over the lazy dog"); |