Skip to content

Instantly share code, notes, and snippets.

Daniel danielborowski

View GitHub Profile
View test.js
// 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);
}
View question_marks.java
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);
View question_marks.py
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
View question_marks.py
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
View example.js
"arrb6???4xxbl5???eee5" => true
"acc?7??sss?3rr1??????5" => true
"5??aaaaaaaaaaaaaaaaaaa?5?5" => false
"9???1???9???1???9" => true
"aa6?9" => false
View noNumbersCorrect.js
// 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;
}
View noNumbers.js
// 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;
}
View removeVowels.js
// 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);
}
}
View removeVowels.js
// 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);
}
}
View hashtable.js
// 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;
}
}
You can’t perform that action at this time.