Skip to content

Commit 7794e81

Browse files
Ariana DavisAriana Davis
authored andcommitted
solution for 1.2
1 parent 17c983f commit 7794e81

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

JavaScript/chapter01/1.1 - Is Unique/solution.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ Output: returns a deduped array of integers
44
*/
55

66
// Solution using Set
7-
87
const isUnique = (arr) => [...new Set(arr)];
98

109
// Test Cases
11-
1210
console.log(isUnique([1,1,1,2,2,2,2,3,3,3,3]) === [1,2,3]);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Given two strings, write a method to decide
2+
if one is permutation of the other */
3+
4+
var checkPerm = function(stringOne, stringTwo) {
5+
//if different lengths, return false
6+
if (stringOne.length !== stringTwo.length ) {
7+
return false;
8+
}
9+
//else sort & compare
10+
else {
11+
var sortStringOne = stringOne.split('').sort('').join('');
12+
var sortStringTwo = stringTwo.split('').sort('').join('');
13+
return sortStringOne === sortStringTwo;
14+
}
15+
};
16+
17+
//Tests
18+
console.log(checkPerm('aba' , 'aab'), true);

0 commit comments

Comments
 (0)