Code Snippets Flashcards
1
Q
Factorial For Loop
A
function FirstFactorial(num) { let factorial = 1 for (let i = 1; i <= num; i++){ factorial *= i; } return factorial }
2
Q
Convert Decimal RGB to Hex Color
A
const rgb = (...arg) => arg .map(it => Math.max(Math.min(it, 255), 0) .toString(16) .padStart(2, '0') .toUpperCase() ).join('');
3
Q
Fibonacci While Loop
A
let a = 1; let b = 0; let temp; while (num>0){ temp=a; a = a+b; b = temp num--; console.log(b)