This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* Greetr JavaScript Library v0.0.1 | |
* | |
* Date: 2017-02-07T11:40Z | |
*/ | |
;(function(global, $){ | |
// 'new' an object | |
var Greetr = function(firstName, lastName, language) { | |
return new Greetr.init(firstName, lastName, language); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Today is : Friday. | |
// Current time is : 4 PM : 50 : 22 | |
var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; | |
var a = new Date(); | |
var hour = a.getHours(); | |
console.log("Today is : " + days[a.getDay()]); | |
console.log("Current time is : " + getH(hour) + " " + a.getMinutes() + ":" + a.getSeconds()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.print(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// console.log(sum(2,3)); // Outputs 5 | |
// console.log(sum(2)(3)); // Outputs 5 | |
function sum(x){ | |
if (arguments.length == 2){ | |
// In functions arguments received as array. | |
// We need to check if their is two or one argument in array. | |
return arguments[0] + arguments[1]; | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// isPalindrome("level"); // Outputs true | |
// isPalindrome("levels"); // Outputs false | |
// isPalindrome("A car, a man, a maraca"); // Outputs true | |
function isPalindrome(str) { | |
// We will replace any non-word character with empty place. | |
// Lowercase all string | |
str = str.replace(/\W/g, '').toLowerCase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// isInteger(3); // Outputs true | |
// isInteger("5"); // Outputs false | |
// isInteger("car"); // Outputs false | |
function isInteger(x) { | |
// ^ stands for XOR so every integer with (4^0) will give integer itself. Every string will give 0 | |
return (x^0) === x; | |
} | |
// Another solution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// f(0); // Outputs 0 | |
// f(5); // Outputs 120 | |
function f(n) { | |
// ? stands for if statement - if n = 1 or less will return - n. if n > 1, then n * f(n-1) | |
// f(n); is recursion function | |
return ((n > 1) ? n * f(n-1) : n) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generally speaking: stabilizing the "this" keyword. | |
var person = {hi: "Hello"}; | |
function showFullName(pep) { | |
console.log (this.hi); | |
} | |
showFullName.call(person); | |
// Output: Hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a function that, given a DOM Element on the page, | |
// will visit the element itself and all of its descendents | |
// (not just its immediate children). For each element visited, | |
// the function should pass that element to a provided callback function. | |
// The arguments to the function should be: | |
// a DOM element | |
// a callback function (that takes a DOM element as its argument) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkNaN(n){ | |
return (n !== n) ? true : false; | |
} | |
/* | |
If we will use regular "isNaN": | |
isNaN(NaN); // true | |
isNaN(undefined); // true | |
isNaN({}); // true | |
isNaN('123ABC'); // true |
OlderNewer