tunnckoCore/starts-with

View on GitHub
benchmark/code/while2.js

Summary

Maintainability
A
0 mins
Test Coverage
/* jshint asi:true */

'use strict'

module.exports = function startsWith (foo, needle) {
  if (Array.isArray(foo)) {
    return foo[0] === needle
  }

  var i = -1
  var len = needle.length

  while (++i < len) {
    if (foo.charAt(i) !== needle.charAt(i)) {
      return false
    }
  }
  return true
}