Skip to content

Instantly share code, notes, and snippets.

// assume we have an array called "list_of_items"
// that contains the names of over 1 million items
// first we'll create a new hash table that will allow
// us to later search for elements very quickly
let hashtable = {};
for (let item of list_of_items) {
if (!hashtable[item]) {
hashtable[item] = true;
}
}
// this function is supposed to take in a string and return
// a new string with all the vowels removed
function removeVowels(str) {
var result = "";
var ignore = ['a', 'e', 'i', 'o', 'u'];
for (var i = 0; i < str.length; i++) {
if (ignore.indexOf(str(i)) === -1) {
result += str(i);
}
}
// this function is supposed to take in a string and return
// a new string with all the vowels removed
function removeVowels(str) {
var result = "";
var ignore = ['a', 'e', 'i', 'o', 'u'];
for (var i = 0; i < str.length; i++) {
if (ignore.indexOf(str(i)) === -1) {
result += str(i);
}
}
// this function should return true if the string contains no numbers
// we are using the isNaN function to determine if a character is a number or not
function noNumbers(str) {
for (var i = 0; i < str.length; i++) {
if (isNaN(str[i])) {
return true;
}
}
return false;
}
// this function will now correctly return true if the string contains no numbers
// otherwise it will return false
function noNumbers(str) {
for (var i = 0; i < str.length; i++) {
if (!isNaN(str[i])) {
return false;
}
}
return true;
}
// assume we have an array called "list_of_items"
// that contains the names of over 1 million items
// first we'll create a new hash table that will allow
// us to later search for elements very quickly
let hashtable = {};
for (let item of list_of_items) {
if (!hashtable[item]) {
hashtable[item] = true;
}
}
def QuestionsMarks(s):
qnum = 0
dig = 0
has_10 = False
for ch in s:
if ch.isdigit():
if int(ch) + dig == 10:
if qnum != 3:
return 'false'
has_10 = True
public static String QuestionsMarks(String str) {
str = str.replaceAll("[a-z]+","");
Pattern pattern = Pattern.compile("([0-9])([?])([?])([?])([0-9])");
Pattern pattern01 = Pattern.compile("([0-9])([?])([?])([0-9])");
Matcher matcher01 = pattern01.matcher(str);
Pattern pattern02 = Pattern.compile("([0-9])([?])([0-9])");
Matcher matcher02 = pattern02.matcher(str);
Matcher matcher = pattern.matcher(str);
def QuestionsMarks(s):
qnum = 0
dig = 0
has_10 = False
for ch in s:
if ch.isdigit():
if int(ch) + dig == 10:
if qnum != 3:
return 'false'
has_10 = True
// interviewer: what will the following code output?
const arr = [10, 12, 15, 21];
for (var i = 0; i < arr.length; i++) {
setTimeout(function() {
console.log('Index: ' + i + ', element: ' + arr[i]);
}, 3000);
}