This file contains hidden or 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
| const fs = require("fs"); | |
| const readline = require('readline'); | |
| /** | |
| * | |
| * @param folderPath | |
| * @param extensions | |
| * @returns {boolean} | |
| */ | |
| const countFilesAndLines = async (folderPath, extensions) => { |
This file contains hidden or 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
| 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) { |
This file contains hidden or 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
| 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); |
This file contains hidden or 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
| 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)); |
This file contains hidden or 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
| 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; |
This file contains hidden or 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
| const cleanText = (_str) => { | |
| const charNames = { | |
| $: "Dollar", | |
| "/": "slash" | |
| } | |
| return _str.split(' ').map((word) => { | |
| return charNames[word] ?? word; | |
| }).join(' '); | |
| } |
This file contains hidden or 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
| /* 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]) { |
This file contains hidden or 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 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'); | |
| } | |
| }) | |
| } |
This file contains hidden or 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
| 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; | |
| } |
This file contains hidden or 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 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; |