Skip to content

Instantly share code, notes, and snippets.

View g-akshay's full-sized avatar
🎯
Bullseye

Akshay Gundewar g-akshay

🎯
Bullseye
View GitHub Profile
@g-akshay
g-akshay / memoized function.js
Created September 2, 2024 09:19 — forked from dlucidone/memoized function.js
memoized function
// a simple pure function to get a value adding 10
const add = (n) => (n + 10);
console.log('Simple call', add(3));
// a simple memoize function that takes in a function
// and returns a memoized function
const memoize = (fn) => {
let cache = {};
return (...args) => {
let n = args[0]; // just taking one argument here
if (n in cache) {
@g-akshay
g-akshay / tripplets.js
Created September 2, 2024 09:18 — forked from dlucidone/tripplets.js
tripplets sum
// Time complexity: O(n^2)
function findTriplets(arr, n) {
arr.sort();
var l = arr.length;
for (var i = 0; i < l; i++) {
var j = i + 1,
k = l - 1;
while (j < k) {
if (arr[i] + arr[j] + arr[k] < n) {
j++;