-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaximum-length-difference.js
More file actions
40 lines (35 loc) · 1.23 KB
/
maximum-length-difference.js
File metadata and controls
40 lines (35 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
You are given two arrays a1 and a2 of strings. Each string is composed with letters from a to z. Let x be any string in the first array and y be any string in the second array.
Find max(abs(length(x) − length(y)))
If a1 and/or a2 are empty return -1 in each language except in Haskell (F#) where you will return Nothing (None).
Example:
a1 = ["hoqq", "bbllkw", "oox", "ejjuyyy", "plmiis", "xxxzgpsssa", "xxwwkktt", "znnnnfqknaz", "qqquuhii", "dvvvwz"]
a2 = ["cccooommaaqqoxii", "gggqaffhhh", "tttoowwwmmww"]
mxdiflg(a1, a2) --> 13
Bash note:
input : 2 strings with substrings separated by ,
output: number as a string
*/
function mxdiflg(a1, a2) {
let retorno = 0
console.log(a1)
console.log(a2)
if (a1.length == 0 || a2.length == 0){
return -1
}
else {
for (let i = 0; i < a1.length; i++){
for (let j = 0; j < a2.length; j++){
if (a1[i].length - a2[j].length < 0){
if ((-1*(a1[i].length - a2[j].length)) > retorno) {
retorno = -1*(a1[i].length - a2[j].length)
}
}
else if (((a1[i].length - a2[j].length)) > retorno) {
retorno = (a1[i].length - a2[j].length)
}
}
}
}
return retorno
}