Created
November 24, 2021 12:34
-
-
Save MohammedALREAI/2de34c7a3e996bae047e3bd384d95ecb to your computer and use it in GitHub Desktop.
HackerRnak permutation soluation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var result = [] | |
function permutation(arr, currentSize) { | |
if (currentSize == 1) { | |
result.push(arr.join("")); | |
return; | |
} | |
for (let i = 0; i < currentSize; i++){ | |
permutation(arr, currentSize - 1); | |
if (currentSize % 2 == 1) { | |
let temp = arr[0]; | |
arr[0] = arr[currentSize - 1]; | |
arr[currentSize - 1] = temp; | |
} else { | |
let temp = arr[i]; | |
arr[i] = arr[currentSize - 1]; | |
arr[currentSize - 1] = temp; | |
} | |
} | |
return result | |
} | |
let newArr = [] | |
function checkDivisibility(arr){ | |
let array = [...arr]; | |
for(let i = 0; i< array.length; i++){ | |
let ww = permutation([...array[i]], [...array[i]].length) | |
// console.log('ww', ww) | |
let me= result.filter(x=>Number(x)%8==0).length | |
var newMe = !!me ?"YES":"NO" | |
console.log(result) | |
newArr.push(newMe) | |
result = [] | |
} | |
; | |
return newArr | |
} | |
// checkDivisibility(["75", "61"]) | |
console.log("ds",checkDivisibility([ "61","75","75", "61"])) | |
// console.log("newArr",newArr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment