Skip to content

Commit dcf85df

Browse files
author
umbur
committed
completes PreSuf
1 parent 21ecc75 commit dcf85df

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

PreSuf.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Create two functions: isPrefix(word, prefix-) and isSuffix(word, -suffix).
2+
// isPrefix should return true if it begins with the prefix argument.
3+
// isSuffix should return true if it ends with the suffix argument.
4+
// Otherwise return false.
5+
6+
// Examples:
7+
// isPrefix("automation", "auto-") ➞ true
8+
// isSuffix("arachnophobia", "-phobia") ➞ true
9+
// isPrefix("retrospect", "sub-") ➞ false
10+
// isSuffix("vocation", "-logy") ➞ false
11+
12+
// Notes:
13+
// The prefix and suffix arguments have dashes - in them.
14+
15+
function isPrefix(word, prefix) {
16+
let testp = prefix.split("").slice(0, -1).join("");
17+
// let testw = word.split("");
18+
// console.log(testp.slice(0).join(""));
19+
return word.startsWith(testp) ? true : false;
20+
// if (testp.slice(0).join("") === testw.slice(0, testp.length).join("")) {
21+
// return true;
22+
// } else {
23+
// return false;
24+
// }
25+
}
26+
27+
function isSuffix(word, suffix) {
28+
let tests = suffix.split("").slice(1).join("");
29+
// console.log(word);
30+
return word.endsWith(tests) ? true : false;
31+
// if (word.endsWith(tests)) {
32+
// return true;
33+
// } else {
34+
// return false;
35+
// }
36+
}
37+
console.log(isPrefix("automation", "auto-"));
38+
// console.log(isSuffix("arachnophobia", "-phobia"));

0 commit comments

Comments
 (0)