1

I was wondering how the syntax of the b.startsWith() function in basil.js is supposed to look.

I want to check all words of a text to see, if they start with the string 'some' (like 'sometimes', 'something', 'someone', 'somewhere' etc.).

So, I create a variable that passes on every word of my text to the b.startsWith() function.

When I put the string I am searching for in the brackets ( b.startsWith(some) ), then where exactly will I have to put the variable that will be checked if it starts with my 'some'-string?

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
mdomino
  • 1,195
  • 1
  • 8
  • 22
  • Make your own. `indexOf` isn’t a good way to go about that check, and `String#startsWith` is coming in ES6. =) `if (!''.startsWith) { String.prototype.startsWith = function(prefix) { return this.substring(0, prefix.length) === prefix; }; }` – Ry- Mar 10 '14 at 05:25

2 Answers2

2

It looks like their documentation has some errors. It shows the function signature as you have described:

b.startsWith(str)

But if you look at the code where the function is defined it looks like this:

var startsWith = pub.startsWith = function(str, prefix) {
  return str.indexOf(prefix) === 0;
};

The first argument is the string to search through, and the second argument is the string to search for.

Sunil D.
  • 17,983
  • 6
  • 53
  • 65
1

There was indeed an error in our documentation. It's fixed now, thanks for letting us know.

So you can use it as

var trueOrFalse = b.startsWith( yourWord, yourSearchToken );