Skip to content

Instantly share code, notes, and snippets.

View kosson's full-sized avatar

Nicolaie Constantinescu kosson

View GitHub Profile
@kosson
kosson / permutations-in-js-exploration.js
Last active May 31, 2023 17:59
Searching for a very efficient solution for permutations on array elements in JavaScript
let listOfArticles = ["HLP63P2I","HLP63P2I","R9T7FVD9","PLI82PFU","M62JFW8Q","W6FXWZHC","URVX9S22","UVF2BX3S","HH3R72BH","EUKZS3QR","PKRP3W4J","56YI28BH","WWZF8Z2V","YKEBAEX7","SB66FSJQ","HHJ739BB","VV26P2K9","ZZIDA78D","NWHASTVQ","RBLMDELC","BUEWZ258","3CQWK77M","WZBL4WV3","ZMPW6UQE","3APZQIYN","3XR95DME","C238ZP3G","PUIK8SYL","PQ7GP3G9","8EGSYTF4","SLEFYRWL","KVBLVJUU","YAPQI5C8","46NMCHCI","MBR34K6L","8K5HT8XM","WGLQYDYA","6MIN5N8G","9K6BU7U4","VWBWABD9","RWHZFBTC","GUBE5PM2","UCZZ7MFD","9T29K75C","J39EPBQU","44AFAI9W","JN8EEGB2"];
console.log(listOfArticles.length);
/* == The functional programming solution == https://stackoverflow.com/questions/43241174/javascript-generating-all-combinations-of-elements-in-a-single-array-in-pairs == */
let firstApproach = listOfArticles.flatMap(
(v, i) => listOfArticles.slice(i+1).map( w => v + ' ' + w )
);
// console.log(firstApproach);
console.log(firstApproach.length);
@kosson
kosson / redincredid.ctrl.js
Created October 21, 2019 08:25
This is how content data generated by Editor.js could be transformed back into html.
const resursaModel = require('../../models/resursa-red');
const competenteS = require('../../models/competenta-specifica');
module.exports = (params) => {
return resursaModel.find({_id: params.idres}).populate({
path: 'competenteS'
}).exec().then( (resursa) => {
// console.log(resursa);
if (resursa[0].content) {
let articleHTML = '';
resursa[0].content.blocks.map(obj => {
// Settings for Atom