function validateThird(input) 299 { 300 //First, generate the array 301 let tmparray = input.trim().split("\n"); 302 let array = []; 303 array[0] = tmparray[0].split(","); 304 array[1] = tmparray[1].split(","); 305 console.log("Parsing array"); 306 console.log(array); 307 if ((array.length === 2) && (array[0].length === 2)) 308 { 309 let diff = Math.abs(parseInt(array[0][0]) - parseInt(array[0][1])); 310 console.log("diff = " + diff); 311 //First, check to see if the weight is included: 312 for (let i = 0; i < array[1].length; ++i) 313 { 314 console.log("Checking " + parseInt(array[1][i])); 315 if (parseInt(array[1][i]) === diff) 316 { 317 return [array[1][i]]; 318 } 319 } 320 //Finally, check to see if any weights added together will equal the diff 321 for (let i = 0; i < array[1].length; ++i) 322 { 323 let tmp = parseInt(array[1][i]); 324 for (let j = i + 1; j < array[1].length; ++j) 325 { 326 if ((tmp + parseInt(array[1][j]) === diff) || (Math.abs(tmp - parseInt(array[1][j])) === diff)) 327 { 328 return [array[1][i], array[1][j]]; 329 } 330 } 331 } 332 return "Not possible"; 333 } 334 else 335 { 336 return "Input must be two arrays; the first of which must be a length of two." 337 } 338 } 339 340 function isVowel(char) 341 { 342 return ((char === 'a') || (char === 'e') || (char === 'i') || (char === 'o') || (char === 'u')); 343 }