Skip to content

Instantly share code, notes, and snippets.

View ankitbtanna's full-sized avatar
💭
Making Videos on Youtube.com/EverydayJavaScript

Ankit Tanna ankitbtanna

💭
Making Videos on Youtube.com/EverydayJavaScript
View GitHub Profile
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function generateRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
@ankitbtanna
ankitbtanna / bmi-calculator.js
Created November 21, 2023 09:36
Atlassian Interview Question - BMI Calculator
function calculateBMI(weight, height) {
// Convert height from centimeters to meters
var heightInMeters = height / 100;
// Calculate BMI using the formula
var bmi = weight / (heightInMeters * heightInMeters);
// Round the BMI to two decimal places
return bmi.toFixed(2);
}
@ankitbtanna
ankitbtanna / cached-api-call.js
Created November 13, 2023 14:37
Atlassian Frontend Software Interview - Cached API call
const cachedApiCall = (time) => {
const cache = {};
return async (url, config = {}) => {
const key = `${url}${JSON.stringify(config)}`;
const entry = cache[key];
if(!entry || Date.now() > entry.expiry){
try{
@ankitbtanna
ankitbtanna / folder-tree-structure.js
Created November 13, 2023 08:56
Atlassian Interview - Recursively parse the folder tree structure
import fetch from 'node-fetch';
async function fetchFileStructure() {
return await fetch('https://api.jsonbin.io/v3/b/64cef151b89b1e2299cc09a2');
}
async function useAndFetchFileStructure() {
try {
const response = await fetchFileStructure();
const fileStructure = await response.json();
@Injectable({ providedIn: 'root' })
export class OfflineService {
constructor(private toast: HotToastService) {
fromEvent(window, 'offline').pipe(
tap(() =>
this.toast.warning('There is no internet connection', {
duration: 10_000,
})
)
).subscribe()
@ankitbtanna
ankitbtanna / template-literal-type.ts
Created June 30, 2021 18:26
TypeScript: Template Literal Types
type SearchScopes = 'All Data' | 'Current Project' | 'My Projects';
type Page = 'PL' | 'Search';
type Search = `${SearchScopes}-${Page}`;
var a: Search = 'All Data-PL'; // Possible combinations = 6
console.log('Add test');