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
// 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 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
// 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 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
// 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 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
// 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 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
// 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; | |
} |
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
// 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 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
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 |
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
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); |
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
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 |
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
// 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); | |
} |
OlderNewer