This file contains 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
// explained | |
function calculateStandardDeviation(numbers) { | |
// Calculate the mean of the array of numbers | |
const mean = numbers.reduce((a, b) => a + b, 0) / numbers.length; | |
// Calculate the differences between the numbers and the mean | |
const differences = numbers.map(num => num - mean); | |
// Square each of the differences | |
const squaredDifferences = differences.map(diff => diff ** 2); |
This file contains 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 (CONFIG) { | |
const make_headlines = (toc, q) => [...toc, q.replace(/----\n###(.*)\n----/g,'* [[#$1]]')]; | |
const post_process = (str) => { | |
const with_headers = str.replace(/\*\*You\*\*:(.*)(\n\n\*\*ChatGPT)/g, "----\n###$1\n----$2") | |
.replace(/\*\*ChatGPT\*\*\:[\s]*/g, "#unconfirmed-chatgpt\n"); | |
const body_text = with_headers.split(/----\n### .*\n----/g).reduce((body, ans) => (ans) | |
? body.replace(ans, ans + '\n[[#Questions asked|Back to Questions]]\n\n') | |
: body, with_headers); | |
const toc = with_headers.match(/----\n\#\#\#.*\n----/g).reduce(make_headlines, ['## Questions asked to GPT', '----']).join('\n'); | |
return [toc, body_text].join('\n\n').trim(); |
This file contains 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 sample_array = [...Array(100)].map((v,i)=>i); | |
const chunk_size = 10; | |
// reuseable reducer: non-destructive | |
const reduce_array_chunks = (size) => ((chunks, val, i)=> { | |
if (i % size) { chunks[Math.floor(i / size)].push(val); } else chunks.push([val]); | |
return chunks; | |
}); | |
const chunk_reducer = reduce_array_chunks(chunk_size); // reusable function option | |
const chunked_by_reduce = sample_array.reduce(chunk_reducer, []); |
This file contains 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 get_string_sanitizer = (user_maps = {}, user_allowed ) => { | |
const build_map = (map_str) => map_str.split(',').map(c => c.split('|')).reduce((dm, [c, r])=> c.split('').reduce((dm, c) => ({...dm, [c]: r.replace('\\u002C', ',')}), {...dm}), {}) | |
const map_strings = { | |
diacritics: '⁰₀⓪⓿0|0,¹₁①⓵❶➀➊1|1,²₂②⓶❷➁➋2|2,³₃③⓷❸➂➌3|3,⁴₄④⓸❹➃➍4|4,⁵₅⑤⓹❺➄➎5|5,⁶₆⑥⓺❻➅➏6|6,⁷₇⑦⓻❼➆➐7|7,⁸₈⑧⓼❽➇➑8|8,⁹₉⑨⓽❾➈➒9|9,⑩⓾❿➉➓|10,⑪⓫|11,⑫⓬|12,⑬⓭|13,⑭⓮|14,⑮⓯|15,⑯⓰|16,⑰⓱|17,⑱⓲|18,⑲⓳|19,⑳⓴|20,ΑÀÁÂÃÄÅĀĂĄƏǍǞǠǺȀȂȦȺᴀḀẠẢẤẦẨẪẬẮẰẲẴẶⒶA|A,ÆǢǼᴁ|AE,ΒƁƂɃʙᴃḂḄḆⒷB|B,ÇĆĈĊČƇȻʗᴄḈⒸC|C,ÈΕÉÊËĒĔĖĘĚƎƐȄȆȨɆᴇḔḖḘḚḜẸẺẼẾỀỂỄỆⒺⱻE|E,ÌÍÎÏĨĪĬĮİƖƗǏȈȊɪᵻḬḮỈỊⒾꟾIΙ|I,ÐĎĐƉƊƋᴅᴆḊḌḎḐḒⒹꝹD|D,ÑŃŅŇŊƝǸȠɴᴎṄṆṈṊⓃNΝ|N,ÒÓÔÕÖØŌŎŐƆƟƠǑǪǬǾȌȎȪȬȮȰᴏᴐṌṎṐṒỌỎỐỒỔỖỘỚỜỞỠỢⓄꝊꝌOΟ|O,ÙÚÛÜŨŪŬŮŰŲƯǓǕǗǙǛȔȖɄᴜᵾṲṴṶṸṺỤỦỨỪỬỮỰⓊU|U,ÝŶŸƳȲɎʏẎỲỴỶỸỾⓎYΥ|Y,ÞꝦ|TH,ß|ss,àáâãäåāăąǎǟǡǻȁȃȧɐəɚᶏᶕḁẚạảấầẩẫậắằẳẵặₐₔⓐⱥⱯa|a,æǣǽᴂ|ae,çćĉċčƈȼɕḉↄⓒꜾꜿc|c,èéêëēĕėęěǝȅȇȩɇɘɛɜɝɞʚᴈᶒᶓᶔḕḗḙḛḝẹẻẽếềểễệₑⓔⱸe|e,ìíîïĩīĭįıǐȉȋɨᴉᵢᵼᶖḭḯỉịⁱⓘi|i,ðďđƌȡɖɗᵭᶁᶑḋḍḏḑḓⓓꝺd|d,ñńņňʼnŋƞǹȵɲɳᵰᶇṅṇṉṋⁿⓝn|n,òóôõöøōŏőơǒǫǭǿȍȏȫȭȯȱɔɵᴖᴗᶗṍṏṑṓọỏốồổỗộớờởỡợₒⓞⱺꝋꝍo|o,ùúûüũūŭůűųưǔǖǘǚǜȕȗʉᵤᶙṳ |