Skip to content

Instantly share code, notes, and snippets.

@kaleem-elahi
Created August 24, 2021 12:14
Show Gist options
  • Save kaleem-elahi/48cc0403c04f20e45498de38b0dfbc2d to your computer and use it in GitHub Desktop.
Save kaleem-elahi/48cc0403c04f20e45498de38b0dfbc2d to your computer and use it in GitHub Desktop.
Interview Question for Anagram
// Coding Questions, and Instructions
// * Please author your code as if it is intended to be shipped to production.
// The details matter. Code will be evaluated on its correctness, simplicity,
// idiomaticity, completeness, and test coverage.
// * Code should be written in JavaScript/NodeJS. You can use a testing
// framework such as Mocha, Jest or Tape, but should not use any other 3rd
// party libraries or frameworks (unless specified).
// * Once you're ready to submit your answers, you should create a secr
// at <https://gist.github.com/> https://gist.github.com and reply to this
// email, with the Gist containing your answers.
// HR Talent5:06 PM
// Question 1
// Write a function called deepClone which takes an object and creates a copy
// of it.
// For e.g. deepClone({ name: "Hitachi MGRM NET", address: { city: "Gurgaon",
// country: "India" } }) -> { name: "Hitachi MGRM NET", address: { city:
// "Gurgaon", country: "India" } }
// Question 2
// Write a function called areAnagrams which takes two string arguments and
// checks whether they are anagrams.
// For e.g. areAnagrams('fried', 'fired') -> true
// Basic test cases are required for all questions
// Que 2:
function areAnagrams(x, y) {
const lengthX = x.length;
const lengthY = y.length;
if(lengthX === lengthY) {
let strX = x.split('').sort().join('');
let strY = y.split('').sort().join('');
console.log(strX === strY);
return strX === strY;
} else {
console.log(false)
return false;
}
}
areAnagrams('frijed', 'fired')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment