js interview questions
by Amir Danish
JavaScript
//5. Given two strings, return true if they are anagrams of one another
var firstWord = "Mary";
var secondWord = "Army";
isAnagram(firstWord, secondWord); // true
function isAnagram(first, second) {
// For case insensitivity, change both words to lowercase.
var a = first.toLowerCase();
var b = second.toLowerCase();
// Sort the strings, and join the resulting array to a string. Compare the results
a = a.split("").sort().join("");
b = b.split("").sort().join("");
return a === b;
}
//******************************************
//6. What will be the output of the following code?
var y = 1;
if (function f() {}) {
y += typeof f;
}
console.log("wahts is the out of of this fun:"+y);