Skip to content

Instantly share code, notes, and snippets.

View ironars's full-sized avatar

Arsalan Ahmed Ansari ironars

  • Karachi
View GitHub Profile
@ironars
ironars / reverseWords.js
Created January 1, 2020 14:09
How to reverse words in a character array
// Input: [
// "J",
// "o",
// "i",
// "n",
// " ",
// "U",
// "s",
// " ",
// "N",
@ironars
ironars / redGreenClosure.js
Last active January 8, 2020 12:11
Write a closure that prints Red and Green alternatively on each call.
const rg = (function () {
let initialValue = 'red';
return function inner() {
console.log(initialValue);
if(initialValue === 'red') {
initialValue = 'green';
} else if (initialValue === 'green') {
initialValue = 'red';
}
}
@ironars
ironars / Find the Saturdays and Sundays between 2 dates
Created March 5, 2020 10:42
Find the Saturdays and Sundays between 2 dates
function getWeekends(start, end) {
var startDate = new Date(start);
var endDate = new Date(end);
var weekendDays = 0;
while (startDate <= endDate) {
var day = startDate.getDay()
if (day == 0 || day == 6) {
weekendDays++;
}