Skip to content

Instantly share code, notes, and snippets.

View mikepenzin's full-sized avatar

Mike Penzin mikepenzin

  • Haifa, Israel
View GitHub Profile
@mikepenzin
mikepenzin / palindrome.js
Created February 28, 2017 15:01
The following function will return true if str is a palindrome; otherwise, it returns false.
// 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();
@mikepenzin
mikepenzin / closures.js
Created February 28, 2017 14:59
JavaScript Closures Example
// 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 {
@mikepenzin
mikepenzin / print.js
Created February 28, 2017 14:59
Send the contents of the current window to printer
window.print();
@mikepenzin
mikepenzin / date_time.js
Created February 28, 2017 14:58
Display Date & Time
// 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());
@mikepenzin
mikepenzin / greetr.js
Created February 7, 2017 15:13
GreetrJS
/*!
* 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);