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
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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('');
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly