Ad
Code
Diff
  • function insertionSort(arr) {
      const filtered = []
      arr.forEach(item => {
        const index = filtered.findIndex(c => c > item)
        index === -1 ? filtered.push(item) : filtered.splice(index, 0, item)
      })
      return filtered
    }
    • function insertionSort(arr) {
    • // return sorted array
    • const filtered = []
    • arr.forEach(item => {
    • const index = filtered.findIndex(c => c > item)
    • index === -1 ? filtered.push(item) : filtered.splice(index, 0, item)
    • })
    • return filtered
    • }
Code
Diff
  • function objectFreeze(a) {
      Object.getOwnPropertySymbols(a).concat(Object.getOwnPropertyNames(a)).forEach(key => {
        Object.defineProperty(a, key, {configurable: false, writable: false, value: a[key]})
      })
      return a
    }
    • // TODO: Create method objectFreeze which works the same as native Object.freeze.
    • // !IMPORTANT: You haven't use Object.freeze during your task
    • function objectFreeze(obj) {
    • return Object.freeze(obj);
    • function objectFreeze(a) {
    • Object.getOwnPropertySymbols(a).concat(Object.getOwnPropertyNames(a)).forEach(key => {
    • Object.defineProperty(a, key, {configurable: false, writable: false, value: a[key]})
    • })
    • return a
    • }