-
-
Save darshanan24/d06d75c6191de215b432ab37e182c94d to your computer and use it in GitHub Desktop.
Common interview questions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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