3 Must-Know Questions #2

// BONUS QUESTION 


const age = (data) => {
    if(data === {age : 18}){
        console.log("You're adult")
    }else if(data == {age : 18}){
        console.log("You're adult")
    }else{
        console.log("AGE LIMITATION")
    }
}


age({age : 18})




//ANAGRAM VALUE OR NOT


const isAnagram = (str1 , str2) => {
   return str1.split('').sort().join('') === str2.split('').sort().join('')
}

console.log('RESULT', isAnagram("FAT", 'ATF'))






// SUM OF DIGITS 

// 456 = 4 + 5 + 6 = 15;



const sumOfDigit = (n) => {
    let sum = 0;


    while(n > 0){
        sum += Math.floor(n%10);
        n = n/10;
    }
    return Math.floor(sum);
}

// n  456 => 45 => 4 => 0 
// sum 0 => 6 => 6 + 5 = 11 => 11 + 4 => 15 

console.log(sumOfDigit(456)) 










//FIBONCAAI SERIES 

// 0,1,1,2,3,5,8

// const fibVal = (num) => {
//     if(num <=1){
//         return num;
//     }else{
//         return fibVal(num - 1) + fibVal(num - 2);
//     }
// }
        // ||OR||

// const fibVal = (num) => {
//    let arr = [0,1];

//    for(let i = 2;i <= num; i++){
//         arr.push(arr[i - 1] + arr[i - 2])
//    }
//    return arr[num]
// }

// console.log(fibVal(6))