From 16975691033ae42175c4a6c18121e38b36469ff5 Mon Sep 17 00:00:00 2001 From: gkucmierz Date: Fri, 8 Sep 2017 23:15:17 +0200 Subject: [PATCH] Are they the same? --- are-they-the-same/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 are-they-the-same/index.js diff --git a/are-they-the-same/index.js b/are-they-the-same/index.js new file mode 100644 index 0000000..1f62a8a --- /dev/null +++ b/are-they-the-same/index.js @@ -0,0 +1,12 @@ +// https://www.codewars.com/kata/are-they-the-same/train/javascript + +function comp(a1, a2) { + if (!a2) return false; + for (let i = 0; i < a1.length; ++i) { + let n = a1[i] * a1[i]; + let idx = a2.indexOf(n); + if (idx < 0) return false; + a2.splice(idx, 1); + } + return (a2 || []).length === 0; +}