DAY 15–07/05/2016

Aayush Bhardwaj
Let’s GOOGLE it !
4 min readMay 8, 2016

Hello ,

Days Completed — 14

Days Left — 163

Act as if what you do makes a difference , it does .

So , today I have to somehow get to a score of 300 in FCC .

But before that GOT S06E02 is out “Home” and John Snow is back , thanks red woman .

And my prediction is right Atletico Madrid has reached the Champions league finale , hard luck Bayern .

FCC — I will be putting down the important concepts for our reference -

  • There are two ways to access the properties of an object : the dot operator (.) and bracket notation ([]), similar to an array.
  • We can delete properties from objects using delete command.
var myDog = {
“name”: “Happy Coder”,
“legs”: 4,
“tails”: 1,
“friends”: [“Free Code Camp Campers”],
“bark”: “woof”
};
delete myDog.tails;

So , I have reached a score of 223 and will be leaving for office now .

So , let’s code again .

  • .hasOwnProperty(propname) method of objects to determine if that object has the given property name.
  • The properties and sub-properties of JSON objects can be accessed by chaining together the dot or bracket notation.
  • JavaScript has a Math.random() function that generates a random decimal number between 0 (inclusive) and not quite up to 1 (exclusive). Thus Math.random()can return a 0 but never quite return a 1 .
  • Math.floor() to round the number down to its nearest whole number.
  • Regular Expressions in JS.
  1. For example, if we wanted to find the word the in the string “The dog chased the cat”, we could use the following regular expression: “/the/gi”
  2. “/” is the start of the regular expression.
  3. the” is the pattern we want to match.
  4. /” is the end of the regular expression.
  5. g means global, which causes the pattern to return all matches in the string, not just the first one.
  6. i means that we want to ignore the case (uppercase or lowercase) when searching for the pattern.
  • The match() method searches a string for a match against a regular expression, and returns the matches, as an Array object.

I wonder why today “Ctrl + Alt + 6” doesn’t seem to be working for Medium . So , not able to add any code snippet .

I have asked Stack Overflow and Quora community for an answer , if there is an alternative way to add a code snippet .

So , for now I am putting the code in Git :

  • We have selectors available for Regular Expression . One such selector is “\d” . It is used to retrieve one digit in a string . “\d+” is used to match one or more digits .
var expression = /\s+/g;
var testString = "Ada Lovelace and Charles Babbage designed the first computer and the software that would have run on it.";
var expressionToGetSoftware = /software/gi;
var softwareCount = testString.match(expressionToGetSoftware).length;
var expression = /and/gi; //Regular Expressionvar andCount = testString.match(expression).length;

Fun Facts :

The only two natural lakes in the world that drains into two different oceans are Lake Isa and Lake Gatun , out of which Lake Isa is a natural lake present in USA and Gatun lake is a man made lake created during the construction of Panama canal .

  • We can also use regular expression selectors like \s to find whitespace in a string , \r (the carriage return), \n (newline), \t (tab), and \f (the form feed).
var expression = /\s+/g;
  • You can invert any match by using the uppercase version of the regular expression selector , For example, \s will match any whitespace, and \S will match anything that isn’t whitespace.
  • Constructor Functions -
  1. You can think of a constructor as a description for the object it will create.
  2. In a constructor the this variable refers to the new object being created by the constructor .
var Bike = function() {  
var gear;
this.getGear = function(){
return gear; };
this.setGear = function(change){
gear = change;
};
};
var myBike = new Bike();
  • Javascript array map() method creates a new array with the results of calling a provided function on every element in this array.
//array.map(callback[, thisObject]);
var oldArray = [1,2,3,4,5];
var newArray = oldArray.map(function(val){
return val+3;
});
OUTPUT :newArray = [4,5,6,7,8]
  • Javascript array reduce() method applies a function simultaneously against two values of the array (from left-to-right) as to reduce it to a single value.
//array.map(callback[, thisObject]);
var array = [4,5,6,7,8];
var singleVal = 0;
singleVal = array.reduce(function(previousVal, currentVal) {
return previousVal + currentVal;
});

So , it’s 19:31 and I have reached a score of 250 .

I think I am done for the day .

GoodBye

--

--