-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringRotation.js
More file actions
28 lines (23 loc) · 795 Bytes
/
stringRotation.js
File metadata and controls
28 lines (23 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Input: two strings, s1 and s2
// output: true if s2 is a rotation of s1. otherwise false
// is case senstitvity important?
function isRotation(s1, s2) {
if (s1.length !== s2.length) return false;
// Easier approach
return (s2 + s2).includes(s1);
// BRUTE BRUTE FORCE APPROACH
// turn s1 and s2 into arrays
// let splitS1 = s1.split('')
// let splitS2 = s2.split('')
// for(let i = 0; i < s1.length - 1; i++){
// let popedVal = splitS1.shift()
// splitS1.push(popedVal)
// if(splitS1.join('') === splitS2.join('')){
// return true
// }
// }
// return false;
}
// isRotation('hello', 'elloh'); //true
// isRotation('hello','olleh') //false
// isRotation('waterbottle','erbottleawt')