Skip to content

Instantly share code, notes, and snippets.

View jasp402's full-sized avatar

jasp402 jasp402

View GitHub Profile
@jasp402
jasp402 / userSchedule.js
Created July 2, 2021 17:37
reordenamiento de un array segun los dias de la semana y las horas dada.
const days = ["Lun","Mar","Mie","Juv","Vie","Sab","Dom"]
const userSchedule = [
[],
['17:00', '18:00', '19:00'],
['17:00', '18:00', '19:00'],
['17:00'],
['17:00', '18:00', '19:00'],
['17:00', '18:00', '19:00'],
[]
];
@jasp402
jasp402 / converData.js
Created June 14, 2021 22:55
Tanformar numeros a fecha
//Input
let d = '210614164612';
//Conver
let year = d.slice(0, 2);
let month = d.slice(2, 4);
let day = d.slice(4, 6);
let hour = d.slice(6, 8);
let min = d.slice(8, 10);
let sec = d.slice(10,12);
@jasp402
jasp402 / 1-e.g.__allEqual.js
Last active August 5, 2020 21:53
JS-PackTools | allEqual
const {allEqual} = require('js-packtools')();
//👇🏻 Check if all the elements of an array are equal
[1, 1, 1, 1, 1, 1, 1, 1].allEqual(); //⇒ true
//👇🏻 If at least one is different then it returns false
[1, 1, 1, 1, 2, 1, 1, 1].allEqual(); //⇒ false
//💡 the same results in a simpler way
@jasp402
jasp402 / 0-e.g.__allEqual.js
Last active August 5, 2020 21:53
JS-PackTools | allEqual
const jsPackTools = require('js-packtools')();
//👇🏻 Check if all the elements of an array are equal
jsPackTools.allEqual([1, 1, 1, 1, 1, 1, 1, 1]); //⇒ true
//👇🏻 If at least one is different then it returns false
jsPackTools.allEqual([1, 1, 1, 1, 2, 1, 1, 1]); //⇒ false
@jasp402
jasp402 / 1-e.g.__capitalLetter.js
Last active August 5, 2020 21:26
JS-PackTools | capitalLetter
const { capitalLetter } = require('js-packtools')();
//👇🏻 Capitalize only the first letter
capitalLetter('hello word'); //⇒ Hello word
//👇🏻 Capitalize all the first letter of each word in the sentence
capitalLetter('hello word', true); //⇒ Hello Word
//💡 ---- tips: you can use prototyping ----
@jasp402
jasp402 / 0-e.g.__capitalLetter.js
Last active August 5, 2020 21:29
JS-PackTools | capitalLetter
const jsPacktools = require("js-packtools")();
//👇🏻 Capitalize only the first letter
jsPacktools.capitalLetter('hello word'); //⇒ Hello word
//👇🏻 Capitalize all the first letter of each word in the sentence
jsPacktools.capitalLetter('hello word', true); //⇒ Hello Word
//📎 This is the most basic way in which this function can be used.
@jasp402
jasp402 / getAllIndexText()
Created June 6, 2020 14:16
JavaScript - Get the index of each word that matches the search.
const getAllIndexText = (str, letter, caseSensitive = false) => {
//all lowercase letters
if (caseSensitive) {
str = str.toLowerCase();
letter = letter.toLowerCase();
}
let arPosition = [];
while (str.indexOf(letter) > -1) {
arPosition.push(str.indexOf(letter));
str = str.replace(letter, '__');
@jasp402
jasp402 / sumAll
Created December 18, 2019 15:47
Sum all numeric elements from array
const assert = require('assert');
selfSum = a => (Array.isArray(a) && eval(a.filter(n => typeof n === 'number').join('+'))) | 0;
describe('TEST # 1 - selfSum()', function () {
it('should, sum all numeric elements', function () {
let arr = [1,2,3,4,5,6,'A'];
assert.equal(selfSum(arr),21);
});
@jasp402
jasp402 / ClassGenerate()
Created October 30, 2019 19:22
Generate Class with Babel
"use strict";
function _instanceof(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
function _classCallCheck(instance, Constructor) {
function pad (n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
function toFormattedDateString(timestamp, includeTime){
if(typeof includeTime == 'undefined'){
includeTime = true;
}