DAY 17–09/05/2016

Aayush Bhardwaj
Let’s GOOGLE it !
3 min readMay 9, 2016

Hello ,

Days Completed — 16

Days Left — 161

It doesn’t matter where you are , you are nowhere compared to where you can go .

Just got up and ready to go Free Code Camping , I start at 250 .

  • The filter method in Javascript is used to iterate through an array and filter out elements where a given condition is not true.
var oldArray = [1,2,3,4,5,6,7,8,9,10];
var newArray = oldArray.filter(function(val){
return val<6;
});
  • You can use the method sort to easily sort the values in an array alphabetically or numerically.
  1. sort can be passed a compare function as a callback. The compare function should return a negative number if a should be before b, a positive number if a should be after b, or 0 if they are equal.
  2. If no compare (callback) function is passed in, it will convert the values to strings and sort alphabetically.
//   Use sort to sort array from largest to smallest.
var array = [1, 12, 21, 2];
array.sort(function (a,b){
return b-a;
});
  • reverse is another array method that alters the array in place, but it also returns the reversed array.
var array = [1, 12, 21, 2];
var newArray;
newArray = array.reverse();
  • concat takes an array as an argument and returns a new array with the elements of this array concatenated onto the end.
var oldArray = [1,2,3];
var newArray = [];
var concatMe = [4,5,6];
newArray = oldArray.concat(concatMe);
  • split uses the argument you pass in as a delimiter to determine which points the string should be split at.
var king = "Hello Brother";
var newArray = [];
newArray = king.split(" ");
  • We can use the join method to join each element of an array into a string separated by whatever delimiter you provide as an argument.
var joinMe = ["Split","me","into","an","array"];
var joinedString = '';
joinedString = joinMe.join(" ");

Oh , it’s a Monday :(

But , I have taken a day off from work :) As , I have some petty works at home and I need to get to a score of 290 in FCC . Presently , standing at 256 , 34 more to go .

Frankly speaking I am a little bored of FCC , looking into the same screen for days now , I ‘ll be taking a short break from FCC once I reach 290 and move to more of Data Structures and Algorithms and coursera pending list .

There are a set of simple algorithms we will be solving as part of JS exercise:

  1. Reverse a String .
  2. Factorial .

[NOTE] Few points on Regular Expressions -

  • A regular expression is an object that describes a pattern of characters.
  • [abc] — Find any character between the brackets
  • [^abc] — Find any non-character b/w the brackets
  • Similarly we have [0–9] and [^0–9]

Then we have meta characters which have a special meaning .

  • \w — word character
  • \W — non-word character
  • \d — digit
  • \D — non-digit

There is a lot more in Regular expressions which we will cover as we go ahead .

[^A-Za-z0–9] — This expression will give me all non-alphanumeric characters.

A simple problem , but cleared a lot of my concepts .

  • sort() is another widely used function in Javascript .

Ques . Find the Longest Word in a String ?

[caution] The callback function of sort() is a little tricky .

And , with this my score for the day is 261 .

Over and Out.

--

--