Between Words

Write a function that takes three string arguments (first, last, word) and returns true if (when alphabetically sorted) word is found between first and last.

Examples

isBetween("apple", "banana", "azure") ➞ true

isBetween("monk", "monument", "monkey") ➞ true

isBetween("bookend", "boolean", "boost") ➞ false

Notes

All letters will be in lowercase.


function isBetween(first, last, word) {
let arr = [first, word, last ]
return arr.join("") === arr.sort().join("")
}

Problem Url: https://edabit.com/challenge/j63YSGGK9xoLiXCKF

Product of Remaining Elements

Write a function that returns true if you can partition an array into one element and the rest, such that this element is equal to the product of all other elements excluding itself.

Examples

canPartition([2, 8, 4, 1]) ➞ true
// 8 = 2 x 4 x 1

canPartition([-1, -10, 1, -2, 20]) ➞ false

canPartition([-1, -20, 5, -1, -2, 2]) ➞ true

Solution:

function canPartition(arr) {
   let positiveArr = arr.map(item => item<0? (-item):item) 
   let index = positiveArr.indexOf(Math.max(...positiveArr)) 
   return arr.filter(num => num ===0).length > 1 || arr[index] === arr.reduce((a,b)=> a*b)/arr[index]
}

Problem Url: https://edabit.com/challenge/WuoMiJRr69hPRQJYx