Skip to content

Instantly share code, notes, and snippets.

@sagnikc395
sagnikc395 / fromTo.js
Created February 12, 2024 19:00
Generator Function In JS ; cassidoo#339
function* fromTo(start,end){
for(let i = start ; i <= end ; i++) {
yield i;
}
}
const range = fromTo(1,3);
console.log(range.next().value);
console.log(range.next().value);
console.log(range.next().value);
@sagnikc395
sagnikc395 / daysBetween.ts
Created January 29, 2024 12:00
days between #337
function daysBetween(date1: string, date2: string) {
let from = new Date(date1);
let to = new Date(date2);
return Math.floor((to-from)/86400000);
}
console.log(daysBetween('Jan 1, 2024', 'Jan 29, 2024'));
console.log(daysBetween('Feb 29, 2020', 'Oct 31, 2023'));
@sagnikc395
sagnikc395 / flip2DArray.ts
Created January 16, 2024 05:38
Flip Array 2D - Cassidoo#335
type Direction = "Vertical" | "Horizontal";
const flipArray = (array: number[][], direction: Direction): number[][] => {
if (direction == "Vertical") {
return array.slice().reverse();
} else {
return array.map((row) => [...row].reverse());
}
};
@sagnikc395
sagnikc395 / possibleSequnces.js
Created January 10, 2024 17:33
#334 of rendezvous with cassidoo. -> all permutations recursion
function combinations(arr) {
const result = [];
function backtrack(start, current) {
result.push([...current]);
for (let i = start; i < arr.length; i++) {
current.push(arr[i]);
backtrack(i + 1, current);

About

I came up with these exercises for someone learning to code. But I thought more people might want to do them.

I like functional programming, so the exercises asks you to make functions that are common in functional programming. If you have learned a language, but want to learn more about functional programming, these exercises are for you.

The exercises were originally meant for Python, but doing them in JavaScript, Ruby or any Lisp (Scheme, Clojure, …) should work just as well. It should also be possible to do them in Java and C#, but it will probably not be as easy.

Most of the functions you are asked to create already exist in functional languages, or libraries for most languages. But it can be educational to implement them yourself.

@sagnikc395
sagnikc395 / returnGiftWindow.ts
Created December 25, 2023 09:19
return gift window - cassidoo solution #332
const returnGiftWindow = (acceptDate: string): Date => {
const res = new Date();
const dt = new Date(acceptDate);
const month = dt.getMonth();
if(month === 11) {
res.setDate(dt.getDate()+90);
}
else {
res.setDate(dt.getDate()+30);
@sagnikc395
sagnikc395 / bitonic.ts
Created December 19, 2023 04:05
check if a array of numbers is a bitonic sequence cassidoo interview ques #331
const isBitonic = (arr: number[]):boolean => {
let left = 0;
let right = 0;
for(let i=0;i<arr.length-1;i++){
left = arr[i];
right = arr[i+1];
if(right<left){
console.log(left);
return true;
@sagnikc395
sagnikc395 / functional_programming_in_JS.md
Created February 10, 2023 06:14 — forked from bigsergey/functional_programming_in_JS.md
Exercises for learning functional programming in JS

Exercises for learning functional programming in JS

During implementation you can use libraries like ramda, lodash, underscore, etc. For each exercise you have to write tests.

Link to presentation: Functional programming in Javascript

First exercise - Reduce

Implement forEach, map, filter, reduceRight and some using only reduce.

@sagnikc395
sagnikc395 / reload.md
Created December 28, 2022 16:53
ssh service reload in macos after restart

Apple does not automatically reloads the ssh-key service after reloading.

To enable the ssh-service to load automatically after reloding into macos:

ssh-key --apple-use-keychain
ssh-key --apple-load-keychain