Skip to content

Instantly share code, notes, and snippets.

View cicconewk's full-sized avatar
🏢
Working

Willker Romero Ciccone cicconewk

🏢
Working
  • Chile
View GitHub Profile
@cicconewk
cicconewk / convertToPalindrome.js
Created May 9, 2019 15:58
Convert to palindrome
function reverseString (str) {
return str.split('').reverse().join('')
}
function palindromeIndex (palindrome_str) {
if (reverseString(palindrome_str) === palindrome_str) {
return -2
}
const strlen = palindrome_str.length
@cicconewk
cicconewk / reverseStrings.js
Created May 9, 2019 16:58
Reverse array of strings
function reverseStrings (strings_array) {
if (!Array.isArray(strings_array)) {
return -1
}
const reversed_strings = strings_array.map(str => str.split('').reverse().join(''))
return reversed_strings
}
@cicconewk
cicconewk / MongooseUniqueValidator.js
Last active April 17, 2020 06:02
#mongoose #unique validator #validator #unique mongoose
Schema.post('save', function (error, doc, next) {
if (error.name === "MongoError" && error.code === 11000) {
const result = {
message: "ValidationError",
errors: {},
};
Object.keys(this._doc).forEach(path => {
const isDuplicate = error.errmsg.includes(`$${path}_1`);
if (isDuplicate) {

Big Os

Check out the original source at ZeroToMastery

O(1) Constant – no loops. O(log N) Logarithmic – usually searching algorithms have log n if they are sorted (Binary Search). O(n) Linear – for loops, while loops through n items. O(n log(n)) Log Linear – usually sorting operations. O(n^2) Quadratic – every element in a collection needs to be compared to ever other element. Two nested loops. O(2^n) Exponential – recursive algorithms that solves a problem of size N. O(n!) Factorial – you are adding a loop for every element.

@cicconewk
cicconewk / big-o-and-scalability.js
Last active February 1, 2022 19:44
It's the first attempt to test the performance of a function that given an array will return a certain value.
const nemo = ["nemo"];
function findNemo(array) {
let t0 = performance.now();
for (let i = 0; i < array.lenght; i++) {
if (array[i] === "nemo") {
console.log("Found NEMO!");
}
}
let t1 = performance.now();