Advertisement
reathh

01. Cognate words

Jul 25th, 2014
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     var words = input[0].split(/\W/).filter(Boolean);
  3.     var foundwords = "";
  4.     var found = false;
  5.     for (var first = 0; first < words.length; first++) {
  6.         for (var second = 0; second < words.length; second++) {
  7.             for (var third = 0; third < words.length; third++) {
  8.                 if (first != second && first != third && second != first && second != third && third != first && third != second) {
  9.                     if (words[first] + words[second] == words[third]) {
  10.                         if (foundwords.indexOf(words[first] + "|" + words[second] + "=" + words[third]) == -1) {
  11.                             foundwords += words[first] + "|" + words[second] + "=" + words[third] + "\n";
  12.                             found = true;
  13.                         }
  14.                     }
  15.                 }
  16.             }
  17.         }
  18.     }
  19.     if (!found) {
  20.         return "No";
  21.     } else {
  22.         return foundwords
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement