-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartsSubstr.js
More file actions
22 lines (16 loc) · 765 Bytes
/
Copy pathstartsSubstr.js
File metadata and controls
22 lines (16 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* -------------------------------------------------------
* Programming Question : Starts with a specific substring
* -------------------------------------------------------
**/
// Q. Write a function to check if a given string stars with a specific substring.
//constraint
// str: A string(e.g. "Hello World")
// substr: A substring to check if it starts the given string (e.g. "Hello")
// Output: true if the given string starts with the specified substring, otherwise false.
function startWith(sent, word) {
// return sent.toLowerCase().startsWith(word.toLowerCase())
return sent.toLowerCase().slice(0, word.length) === word.toLowerCase();
}
console.log(startWith("Hello World", "hello"));
console.log(startWith("Hello World", "world"));