Last active
April 10, 2018 17:38
-
-
Save niradler/11b885f9b23a6b12bf9589732086abf1 to your computer and use it in GitHub Desktop.
wix recruitment day
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
/* question A, | |
params : A = [1,6,4,5,8,10] | |
return : sum max triangle sides | |
a + b > c | |
*/ | |
const solution = (A)=>{ | |
const find_triplet = (sorted_arr) => { | |
for (let i = sorted_arr.length - 1; i > 1; i--) { | |
const c = sorted_arr[i] | |
const b = sorted_arr[i - 1] | |
const a = sorted_arr[i - 2]; | |
if (a + b > c) | |
return a + b + c; | |
} | |
return -1 | |
} | |
const sorted_arr = A.sort((a,b)=>a>b) | |
const max_tri = find_triplet(sorted_arr); | |
return max_tri; | |
} | |
const A = [1,6,4,5,8,10]; | |
const answer = solution(A); | |
console.log(answer); | |
/* question B, | |
params : S (String), T (String) | |
return : is match ignore ? | |
*/ | |
const solution = (S, T) => { | |
const str_to_arr = (str) => { | |
let temp_str = []; | |
for (let i = 0; i < str.length; i++) { | |
const char = str[i]; | |
if (isNaN(char)) { | |
temp_str.push(char) | |
} else { | |
let number_of_err = char, | |
new_str = str.substring(i + 1, str.length); | |
for (let j of new_str) { | |
if (isNaN(j) === false) { | |
i++; | |
number_of_err = number_of_err + j; | |
} else { | |
break; | |
} | |
} | |
const arr_to_add = (new Array(Number(number_of_err))).fill('?') | |
temp_str = temp_str.concat(arr_to_add) | |
} | |
} | |
return temp_str; | |
} | |
const s_arr = str_to_arr(S); | |
const t_arr = str_to_arr(T); | |
if (s_arr.length != t_arr.length) | |
return false; | |
for (let i = 0; i < s_arr.length; i++) { | |
if (s_arr[i] == t_arr[i] || (s_arr[i] == '?' || t_arr[i] == '?')) | |
continue; | |
else { | |
return false; | |
} | |
} | |
return true; | |
} | |
const answer = solution("a2l12g", "appl12g"); | |
console.log(answer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment