Skip to content

Instantly share code, notes, and snippets.

View briyithhhh's full-sized avatar
🏠
Working from home

Briyith Portillo briyithhhh

🏠
Working from home
  • URBE Unversity
  • Zulia, Venezuela
  • 18:36 (UTC -04:00)
  • X @briyitosss
View GitHub Profile
@briyithhhh
briyithhhh / diamond.js
Last active December 15, 2022 19:54
diamond-pattern
const n = 5
for (let i = 1; i <= n; i++){
for(let j = 1; j <= n - i; j++){
process.stdout.write(' ')
}
for(let k = 0; k < 2 * i - 1; k++){
process.stdout.write('*')
}
console.log()
@javierd79
javierd79 / REGEXes.js
Last active October 3, 2022 03:15
REGEXes to use in JS vanilla and React Project
/* REGEXes */
const REGEX_INT = /^-?\d+$/;
const REGEX_EMAIL = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/g;
const REGEX_PASSWORD = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/gm;
const REGEX_IPv4 = /\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b/ig;
const REGEX_IPv6 = /(([a-fA-F0-9]{1,4}|):){1,7}([a-fA-F0-9]{1,4}|:)/gm;
@javierd79
javierd79 / protectedRoutes.js
Last active October 2, 2022 18:42
control access in an APP with React
const permissions = {
Admin: ['/', '/users'],
undefined: ['/login'],
null: ['/login'],
};
const initialState = {
status: false,
};
@javierd79
javierd79 / concatArrays.js
Created October 2, 2022 18:31
Concat two different arrays
function concatArrays (firstArr, secondArr) {
return [...firstArr, ...secondArr]
}
concatArrays ([1,2,3], ["Hello world!", "Mondongo"])
// [ 1, 2, 3, 'Hello world!', 'Mondongo' ]
@javierd79
javierd79 / countDuplicate.js
Created September 24, 2022 21:17
Function to count how many elements are duplicates in an Array
const countDuplicate = (array) => {
let object = array.reduce((prev, cur) => ((prev[cur] = prev[cur] + 1 || 1), prev), {})
console.log(object);
}
countDuplicate(['test', 'test', 'test2'])
@javierd79
javierd79 / fakeBinary.js
Last active September 25, 2022 21:21
The function called fakeBinary receives as argument size(size) which is a number (integer) and must return a string of 1s and 0s with the indicated size.
let result = []
const REGEX_INT = /^-?\d+$/;
const isNumber = (value) => {
return REGEX_INT.test(value);
}
const fakeBinary = (param) => {
if (isNumber(param)){
@javierd79
javierd79 / date.js
Last active September 25, 2022 21:21
Snippet to get one day of the week every week in React.Js
export const everyWeek = (x) => {
let prev = new Date();
prev.setDate(prev.getDate() + (x+(7+prev.getDay())) % 7);
return prev
.toISOString()
.slice(0, 10)
.replace('T',' ');
}