diff --git a/algorithms/JavaScript/src/arrays/single-occurring-element.js b/algorithms/JavaScript/src/arrays/single-occurring-element.js index ece2949b..4af542f9 100644 --- a/algorithms/JavaScript/src/arrays/single-occurring-element.js +++ b/algorithms/JavaScript/src/arrays/single-occurring-element.js @@ -1,14 +1,15 @@ -// Problem: Given an array of integers, every element appears twice except for one. Find that single one. +// Problem: Given an array of integers, +// every element appears twice except for one. Find that single one. // Space Complexity: O(1) // Time Complexity: O(n) function singleOccurringElement(arr) { - let result = 0; - for(let el of arr) { - result ^= el; - } - return result; + let result = 0; + for (const el of arr) { + result ^= el; + } + return result; } const arr = [2, 5, 7, 3, 1, 8, 8, 9, 4, 2, 7, 1, 4, 9, 5]; -console.log(singleOccurringElement(arr)); \ No newline at end of file +console.log(singleOccurringElement(arr));