Monday, February 29, 2016

RETURN LARGEST NUMBERS IN ARRAY

Challenge here was to return an array consisting of the largest number from each provided sub-array. The provided array contained exactly 4 sub-arrays.

For example: 

[[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]];

An array is a container object that holds a fixed number of values of a single type. In our e.g array is array of arrays.

Initial I misunderstood the challenge. I thought that the challenge requires to return the Array that is having maximum value number in it. I struggled whole of the day until I reexamined the challenge.

The requirement here was to make an Array from this Array of Array, that contained only the greatest value in each sub-Array.

Then on it was a cake walk for me because I already struggled a lot through out the day.

So, here is my solution:

function largestOfFour(arr) {     var arr1 =[];     for (var i = 0; i < arr.length; i++ ){         a = arr[i];         var max = 0;                  for (var j = 0; j < a.length; j++){             var b = a[j];             if(b > max){                 max = b;             }        }    arr1.push(max);   } return arr1; }

Sunday, February 28, 2016

TITLE CASE A SENTENCE

Today's challenge was to return the provided string with the first letter of each word capitalized. The rest of the words are to be in lower case.

For e.g     If input is following string.

                "I'm a little tea pot"

The output should be

                 "I'm A Little Tea Pot"

I  finally succeeded in implementing the solution. Although I was tempted to look for solution in google, but I kept on revising by solutions based on output at every step using "console.log()". Finally my solution was accepted. I know at lot can be improved in my solution. but this solution is my solution and is not a copy paste from google.

Here is my solution:-
 
  function titleCase(str) {
  
   var arr = str.toLowerCase().split(' ');
   arr1 = [];
   
   for (var i = 0; i < arr.length; i++){
           var newArr = arr[i].split('');
           
           var j = newArr[0].toUpperCase();


           newArr.shift();
           
           var k = newArr.unshift(j);
           
           arr1.push(newArr.join(''));          
           
   }
  return arr1.join(' ');
}

titleCase("I'm a little tea pot");

FIND THE LONGEST WORD IN A STRING

Challenge is to return the length of the longest word in the provided sentence.

Response should be a number.

It was tough one for me initially then i went through a post on git-hub describing what to do when you are struck up. I am putting the link here for reference.
  

This is a three part series. A must read for all the new coder. My next step was to make a flow chart. but in part II of the series, the above mentioned challenge is discussed with flow chart along with pseudo-code. It helped me a a lot. With the help of this pseudo-code, I quickly came up the solution. 

My solution is given below



 function findLongestWord(str) {
     var arr = str.split(' ');
     var max = 0; 
    for (var i = 0; i < arr.length; i++){
        var item = arr[i].length;
  
         if (item > max){
             max = item;
          }
  }  
   return max;  
}

Saturday, February 27, 2016

CHECK FOR PALINDROMES

 A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.

Challenge is to return true if the given string is a palindrome. Otherwise, return false.

It took me a while to solve this challenge. It could pass all the test except 

palindrome("1 eye for of 1 eye.") should return false.

The problem was I was discarding digits 0-9 in my regex expression.

I amended the regex expression from /[^a-b]/gi to /[^a-b0-9]/gi to include the digits into the stripped version.

Behold I cracked it.....

Here is my implementation:



function palindrome(str) {
  
  var stripped = str.toLowerCase().replace(/[^a-z0-9]/gi, '');
  var reversed = stripped.split('').reverse().join('');
   
  if (stripped === reversed){
    return true;
   } else {
     return false;
  }
  
}

FACTORIALIZE A NUMBER

Challenge here is to return the factorial of the provided integer.

If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n.

Factorials are often represented with the shorthand notation n!

For example: 5! = 1 * 2 * 3 * 4 * 5 = 120


This challenge requires a thorough knowledge of loops, and how to store the value returned by a loop. In my case "result" is storing variable after ever loop.

It took me a while I was looping correctly, but not storing the result. Getting very high output due to multiplication.

 Here is my solution:


 function factorialize(num) {
   result = 1;
   for (var i = 1; i <= num; i++){
    result *= i;
  }
  return result;
}

factorialize(5);

BASIC ALGORITHM SCRIPTING

I have already completed basic HTML, CSS, JavaScript Tutorials on FreeCodeCamp.com. Now I am into Basic Algorithm Scripting challenges.

First challenge is to reverse the Strings.

Here is my Solution which I managed to complete in first attempt.

Reverse the input String


function reverseString(str){ 

  arr = str.split('').reverse().join('');
  return arr;
  
}

reverseString("hello");


Tuesday, February 23, 2016

HOW TO BE A SELF TAUGHT WEB DEVELOPER.

STEP BY STEP BREAKUP MONTH WISE
This is rough draft that we will be following:
Will be improved as we go.

MONTH 1 (Basics)
Languages: HTML and CSS
Resources: Codeacademy.com, Htmldog.com
Project: Bulid your personal page.

MONTH 2 and 3 (Front-End Development)
Languages: Javascript and jQuery
Resources: Eloquent Javascript - ebook
docs.jquery.com/Tutorials
Project: Build your portfolio website

MONTH 4 and 5 (Back-End Development)
Languages: php or rails
Resources: codeacademy.com railtutorial.com
Project: Improving Portfolio website

MONTH 6
Miscellaneous: Version control using Git
Deployment of web apps on the web