Skip to content

Instantly share code, notes, and snippets.

@darshanan24
Last active November 24, 2018 15:28
Show Gist options
  • Save darshanan24/d06d75c6191de215b432ab37e182c94d to your computer and use it in GitHub Desktop.
Save darshanan24/d06d75c6191de215b432ab37e182c94d to your computer and use it in GitHub Desktop.
Common interview questions
1. given a string calculate the number of repeated words and return a value.
var fruits = "orange banana orange mango"
function sting(str){
var n = str.match(/orange/g);
console.log(n.length)
}
sting(fruits)
2. copy the file and dump a string to file.
function haproxy(username, password) {
User.findOne({
username:username
}).exec().then(user => {
const str = `user ${ username } insecure-password ${ password }\n`;
fs.renameSync('message.txt', 'message.txt.bak');
fs.appendFile('message.txt', str, function (err) {
if (err) throw err;
console.log('Saved!');
});
}).catch(error => {
next(errorBuilder.badRequest(error));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment