Skip to content

Instantly share code, notes, and snippets.

View jafar-jabr's full-sized avatar
🎯
Focusing

Jafar Jabr jafar-jabr

🎯
Focusing
View GitHub Profile
@jafar-jabr
jafar-jabr / index.js
Last active March 5, 2022 02:11
Count files and lines
const fs = require("fs");
const readline = require('readline');
/**
*
* @param folderPath
* @param extensions
* @returns {boolean}
*/
const countFilesAndLines = async (folderPath, extensions) => {
@jafar-jabr
jafar-jabr / index.js
Last active February 27, 2022 12:53
hijriToCalendars versions performance compare
const performanceCompare = (callBack1, callBack2, amplifier=1000000) => {
const t1 = performance.now();
callBack1();
const t2 = performance.now();
const t3 = performance.now();
callBack2();
const t4 = performance.now();
const perform1 = ~~(t2-t1);
const perform2 = ~~(t4-t3);
if(perform1 || perform2) {
@jafar-jabr
jafar-jabr / index.js
Last active February 27, 2022 14:20
performanceCompare
const performanceCompare = (callBack1, callBack2, amplifier=10000) => {
callBack1();
callBack2();
const t1 = performance.now();
callBack1();
const t2 = performance.now();
const t3 = performance.now();
callBack2();
const t4 = performance.now();
const perform1 = ~~(t2-t1);
@jafar-jabr
jafar-jabr / index.js
Last active July 29, 2022 23:18
Convert Hijri date to Gregorian
const HijriToGregorian = (hijriDate) => {
const handelAmericanFormat = (_date) => {
const [month, day, year] = _date.split('/');
return new Date(Date.UTC(year, month, day));
};
const addDays = (_date, days) => {
let date;
if (typeof _date === 'string') {
const [month, day, year] = _date.split('/');
date = new Date(Date.UTC(year, month, day));
@jafar-jabr
jafar-jabr / index.js
Created January 26, 2022 15:37
closest to zero
const closestToZero = (_arr) => {
let closest = _arr[0] ?? 0;
_arr.forEach((item) => {
if(item <= Math.abs(closest) && item > 0){
closest = item;
}else if(Math.abs(item) < Math.abs(closest)){
closest = item;
}
});
return closest;
@jafar-jabr
jafar-jabr / index.js
Created January 21, 2022 22:05
clean text
const cleanText = (_str) => {
const charNames = {
$: "Dollar",
"/": "slash"
}
return _str.split(' ').map((word) => {
return charNames[word] ?? word;
}).join(' ');
}
@jafar-jabr
jafar-jabr / maxTicket.js
Last active December 24, 2021 23:20
javascript picking tickets (maxTicket)
/* complete the function maxTicket to return the maximum subsqeunces in the given array,
where the maximum absilute difference between elemnts in one subsqeunce j and j+1 is either 0 or 1 */
const maxTicket = (s) => {
let subsequences = {};
s.forEach((ss) => {
subsequences[ss] = subsequences[ss] ? [...subsequences[ss], ss]: [ss];
if(subsequences[ss+1]) {
subsequences[ss+1] = [...subsequences[ss+1], ss];
}
if(subsequences[ss-1]) {
@jafar-jabr
jafar-jabr / common_substring.js
Last active December 18, 2021 09:33
Javascript common substring
function commonSubstring(a, b) {
a.forEach((row, index) => {
const otherString = b[index] ?? '';
if(row.split('').some((letter) => otherString.indexOf(letter) !== -1)) {
console.log('YES');
}else{
console.log('NO');
}
})
}
@jafar-jabr
jafar-jabr / first_unique_character.js
Last active December 27, 2021 12:17
Javascript get first unique character
const firstUniqChar = (_str) => {
for (let i= 0; i < _str.length; i+= 1) {
if (_str.indexOf(_str[i]) === _str.lastIndexOf(_str[i])) return i+1;
}
return -1;
}
@jafar-jabr
jafar-jabr / countries.sql
Created May 16, 2019 22:34 — forked from adhipg/countries.sql
Sql dump of all the Countries, Country Codes, Phone codes.
CREATE TABLE IF NOT EXISTS `country` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`iso` char(2) NOT NULL,
`name` varchar(80) NOT NULL,
`nicename` varchar(80) NOT NULL,
`iso3` char(3) DEFAULT NULL,
`numcode` smallint(6) DEFAULT NULL,
`phonecode` int(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;