Skip to content

Instantly share code, notes, and snippets.

View bytao7mao's full-sized avatar
🐢
Being lazy

Marius Nicolae bytao7mao

🐢
Being lazy
View GitHub Profile
@bytao7mao
bytao7mao / Costrunctor Js
Created August 12, 2017 12:59
Constructor Js
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");
@bytao7mao
bytao7mao / radius ,area and perimeter
Created August 12, 2017 14:17
radius ,area and perimeter
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;
}
@bytao7mao
bytao7mao / adress book [i]
Created August 12, 2017 16:08
adress book [i]
var bob = {
firstName: "Bob",
lastName: "Jones",
phoneNumber: "(650) 777-7777",
email: "bob.jones@example.com"
};
var mary = {
firstName: "Mary",
lastName: "Johnson",
@bytao7mao
bytao7mao / longest array(+number)
Created August 13, 2017 02:35
longest array(+number)
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;
@bytao7mao
bytao7mao / JS push and sort
Created August 14, 2017 00:32
JS push and sort
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
}
@bytao7mao
bytao7mao / even and odd JS
Created August 15, 2017 13:28
even and odd JS
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);
@bytao7mao
bytao7mao / map function JS
Created August 17, 2017 03:05
map function JS
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);
@bytao7mao
bytao7mao / prototypes
Created August 18, 2017 08:58
prototypes
// 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);
@bytao7mao
bytao7mao / returning elements from array
Last active August 18, 2017 12:13
returning elements from array
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'];
@bytao7mao
bytao7mao / longest word
Last active August 18, 2017 14:45
longest word
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");