Skip to main content

Posts

Showing posts with the label javascript functions

Compare two arrays

Tutorial on comparing two arrays Let's talk about comparing two array against each other and returning values that they have in common or values that they don't. A bit of back story -- writing a function that will return common values was pretty easy for me to come up with however, returning unique values gave me some trouble and I spent quite a lot of time researching it. Eventually I found this neat  solution  and honestly I am not completely sure if I would get to it myself since I haven't been working enough with objects or this type of statement. Therefore, I will be going back to basics and I am planning to go through the Statements  section on MDN. The solutions  By using  For In...  statement we can solve both problems and I am still trying to figure out if it's possible to apply  For Loop in the unique values function. Return common values I used here a  For Loop on both vowels and str  arrays (string becomes an arr...

Empty input in a function

Tutorial on an empty input in a function. I was doing this challenge on Code Wars where I had to "Return null if param is null or array is empty." This caused me some trouble and took me a while to figure out how to write a condition for an empty input in a function. This is something I came up with and it worked for me: It was interesting for me to find a way to write it this way where basically it test if the value has no length which seem pretty obvious right now.

JavaScript Functions

[3/100] Today was busy and I had an only an hour or so in the evening to sit down and continue JS overview. I did additional small work on Wix but cannot really call it coding... I gave myself a promise and even if it means giving it only 5 minutes I am gonna write a line of code everyday. I am continuing Colt's bootcamp on Udemy. We have been going over JS functions and their structure which is: function function_name ( argument /empty) { doSomething; } There are also two ways of defining a function: Function declaration  function capitalize(str) {   return str.charAt(0). toUpperCase () + str. slice (1); } Function expression var capitalize = function (str) {   return str. charA t(0). toUpperCase () + str. slice (1); } I am familiar with the concept and the exercises went pretty smoothly, however I had a tough time with writing a function that was supposed to return a factorial of a number. I could not figure out how it ...