Skip to content

Instantly share code, notes, and snippets.

@MohammedALREAI
Created November 24, 2021 12:34
Show Gist options
  • Save MohammedALREAI/2de34c7a3e996bae047e3bd384d95ecb to your computer and use it in GitHub Desktop.
Save MohammedALREAI/2de34c7a3e996bae047e3bd384d95ecb to your computer and use it in GitHub Desktop.
HackerRnak permutation soluation
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