Find All Words Which are Greater Than Given Length X in String Using JavaScript

0Shares

main.js

<script>
// javascript program to find all string
// which are greater than given length k

  // function find string greater than
  // length x
  function string_x( s , x) {
    // create the empty string
    var w = "";

    // iterate the loop till every space
    for (i = 0; i < s.length; i++) {
      if (s.charAt(i) != ' ')

        // append this sub string in
        // string w
        w = w + s.charAt(i);
      else {

        // if length of current sub
        // string w is greater than
        // x then print
        if (w.length > x)
          document.write(w + "<br />");
        w = "";
      }
    }
  }

  // Provide function parameters and execute the function
  var s = "Edopedia - Become a Better Software Developer";
  var x = 7;
  s = s + " ";
  string_x(s, x);
</script>

Output

Edopedia
Software
Developer
0Shares

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.