Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [


{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"${workspaceFolder}/tests.js"
],
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": [
"<node_internals>/**",
"${workspaceFolder}/node_modules/**/*"
]
}
]
}
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function stringIncludes(haystack, needle) {
for (let i = 0; i < haystack.length; i++) {
if (haystack.slice(i, needle.length) === needle) {
if (haystack.slice(i, i + needle.length) === needle) {
return true
}
}
Expand All @@ -10,13 +10,12 @@ function stringIncludes(haystack, needle) {

function countLetter(haystack, needle) {
let count = 0
for (let i = 0; i < haystack.length; i++) {
if (haystack.slice(i, i + needle.length) === needle) {
Comment on lines +13 to +14

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also could have used .split() to turn the string into an array and then the .shift() would have worked as expected


while (haystack.length) {
if (haystack.shift() === needle) {
count++
}
}

return count
}

Expand All @@ -39,4 +38,5 @@ module.exports = {
stringIncludes,
countLetter,
camelCase,

}
Loading