Wednesday, October 21, 2015

Bonfire : Check for Palindrome.

They mention here that we should remove all punctuation marks in the string.

Here are the strings  in the Bonfire test cases with punctuation marks.
"A man, a plan, a canal. Panama"
"My age is 0, 0 si ega ym."
"0_0 (: /-\ :) 0-0"


Used little bit of stackoverflow and MDN to understand .replace()
This is what I got:

Used a lot of console to debug each string and that really helped.



Code starts here

function palindrome(str) {
  
  // Good luck!
  //Removing punctuation marks and spaces in original string..
  var originalstring = str.replace(/[.,-\/#!$%\^&\*;:{}=\-_`~() " "]/gi,"").toLowerCase();
  var reversedstring = str.replace(/[.,-\/#!$%\^&\*;:{}=\-_`~() " "]/gi,"").toLowerCase().split("").reverse().join('');
  if(reversedstring === originalstring)
    {
  return true;
    }
  else
    {
      return false;
    }
}




palindrome("eye");






Factorial of Number Bonfire Solution

Used a while loop for this and it worked ok.

function factorialize(num) {
  factorial = 1;
  i = 1;
  while(i<=num)
    {
      factorial = factorial * i;
      i++;
    }
  return factorial;
}

factorialize(5);

Bonfire Reverse a String.

Was able to solve this using MDN examples and console.log() in chrome browser.
Solution:


function reverseString(str) {
 
  return str.split("").reverse().join('');
}

reverseString("hello");


Tuesday, October 20, 2015

Here goes the story for starting this blog.
1.There is not much going on at work and the next release for my project is slated to start Novemeber mid so I have a lot of time to kill, so  i thought why not learn D3.js.
I currently work with QlikView and feel extremely frustrated at some of the limitations for the visualization we can do with it.
Took a look at D3. js charts by Mike Bostock and woah, I'm like I want to be able to create them from scratch.

Also my coding skills have gotten little rusty over the past two years and hence learning D3 as a ruse to sharpen them.
Started with CodeAcademy but i felt its okay for learning syntax and basics for JS,HTML and CSS.

I came across freecodecamp after that now Im totally absorbed doing these Bonfire challenges.

Feeling really bad that I didnt get to do such stuff in my Engineering.
Also i started learning Python with Coursera's Rice University Course but I get distracted really easily.

FreecodeCamp is working out good so far because i like to learn by doing stuff.

On the work front I still have loads to learn, but need to make time for it.

Bonfire : Where do I Belong

function where(arr, num) {
  // Find my place in this sorted array.
   arr.sort(function(a, b) {
  return a - b;
});
 
//at this point the array is all sorted
 //the below function gets the maxnumber in the array
  function maxnumberinarray( array ){
    return Math.max.apply( Math, array );
};
  if(num>maxnumberinarray(arr)){
    return arr.length;
  }
  var pos = 0;
  for(i=0;i<arr.length;i++)
    {
      if(arr[i]<num){
        pos = i+1;
      }
      else {
      return pos;
      }
    }
}

where([10, 20, 30, 40, 50], 35)