From a9ebf91c355db17a3f09d412a0803825dbc0e8e1 Mon Sep 17 00:00:00 2001 From: Mary Date: Tue, 11 Dec 2018 14:36:21 -0500 Subject: [PATCH] Update checkPermute.js --- chapter01/1.2 - Check Perm/checkPermute.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/chapter01/1.2 - Check Perm/checkPermute.js b/chapter01/1.2 - Check Perm/checkPermute.js index 0cb0931..d3f19a7 100644 --- a/chapter01/1.2 - Check Perm/checkPermute.js +++ b/chapter01/1.2 - Check Perm/checkPermute.js @@ -16,4 +16,19 @@ console.log(checkPermute('aba', 'aab'), true); console.log(checkPermute('aba', 'aaba'), false); -console.log(checkPermute('aba', 'aa'), false); \ No newline at end of file +console.log(checkPermute('aba', 'aa'), false); + +//Another solution + +function permutation(str1, str2) { + if (str1.length !== str2.length) { + return false; + } + + for (var i = 0; i < str1.length; i++) { + if (!str2.includes(str1.charAt(i))) { + return false; + } + }; + return true; +}